8 Replies - 517 Views - Last Post: 01 April 2012 - 03:03 PM Rate Topic: -----

#1 so0oma  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 93
  • Joined: 01-January 11

dynamic table (php &mysql)

Posted 01 April 2012 - 08:42 AM

hi ,
I am not very experienced in programming php and mySQL but I think the question I have should be quite simple to answer... only I don't get it!
I am trying to create a table that reads information from a MySQL database, I would like it to display a course which have want to be display in the current semester
i add a column have yes or no
then display in the table
this is my work :

<?php 	  
	include('con-db.php');
    $query = "SELECT * from selected selected_course".
	" WHERE  selected_course.check = s_post['true'] ";
	$result = mysql_query($query) or die(mysql_error());
 while($r=mysql_fetch_array($result))
   {

          echo"<tr><td><center>".$r['coursename']."</td></center</tr>";

}
?>



and the table have the result is :
<table border="2" width="51%" bordercolorlight="#996633" bordercolordark="#5A3A0B" bordercolor="#5A3A0B">
		<tr>
			<td width="29"><font color="#5A3A0B">No.</font></td>
			
			<td width="411">
			<p align="center"><font color="#5A3A0B">Course Title and Code</font></td>
			<td width="29"><font color="#5A3A0B">Rate</font></td>
		</tr>
		</table>


Is This A Good Question/Topic? 0
  • +

Replies To: dynamic table (php &mysql)

#2 4D1  Icon User is offline

  • D.I.C Head

Reputation: 22
  • View blog
  • Posts: 224
  • Joined: 22-October 09

Re: dynamic table (php &mysql)

Posted 01 April 2012 - 09:21 AM

So whats the problem?

By the way <font> is deprecated, you should use styles instead and you may need a comma between 'from selected, selected_course'.
Was This Post Helpful? 0
  • +
  • -

#3 so0oma  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 93
  • Joined: 01-January 11

Re: dynamic table (php &mysql)

Posted 01 April 2012 - 09:23 AM

the problem about the rows don't appear in the table
how can do it ?
Was This Post Helpful? 0
  • +
  • -

#4 CTphpnwb  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 2485
  • View blog
  • Posts: 8,523
  • Joined: 08-August 08

Re: dynamic table (php &mysql)

Posted 01 April 2012 - 09:26 AM

What is this?
s_post['true']

If you meant to do:
$_POST['true']

that's wrong, since you should never put user supplied data into a query. Read up on prepared statements.
Was This Post Helpful? 0
  • +
  • -

#5 4D1  Icon User is offline

  • D.I.C Head

Reputation: 22
  • View blog
  • Posts: 224
  • Joined: 22-October 09

Re: dynamic table (php &mysql)

Posted 01 April 2012 - 09:28 AM

The same way you did when you echoed the coursename result out, but in the table...
Was This Post Helpful? 0
  • +
  • -

#6 so0oma  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 93
  • Joined: 01-January 11

Re: dynamic table (php &mysql)

Posted 01 April 2012 - 09:49 AM

i try to correct but still error
can you help
<?php 	  
	include('con-db.php');
    $query = "SELECT coursename".
	"from selected_course".
	" WHERE  selected_course.check = 'true' ";
	$result = mysql_query($query) or die(mysql_error());
 while($r=mysql_fetch_array($result))
   {

          echo"<tr><td><center>".$r['coursename']."</td></center</tr>";

}
?>

Was This Post Helpful? 0
  • +
  • -

#7 4D1  Icon User is offline

  • D.I.C Head

Reputation: 22
  • View blog
  • Posts: 224
  • Joined: 22-October 09

Re: dynamic table (php &mysql)

Posted 01 April 2012 - 11:31 AM

No one can help you because you are not explaining your problem!

You have some code that is not working, why is it not working? what errors are you getting? what should it do? what is it doing?
Was This Post Helpful? 0
  • +
  • -

#8 CTphpnwb  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 2485
  • View blog
  • Posts: 8,523
  • Joined: 08-August 08

Re: dynamic table (php &mysql)

Posted 01 April 2012 - 01:58 PM

And what is the type of selected_course.check? Is it text or varchar?
Was This Post Helpful? 0
  • +
  • -

#9 e_i_pi  Icon User is offline

  • = -1
  • member icon

Reputation: 745
  • View blog
  • Posts: 1,521
  • Joined: 30-January 09

Re: dynamic table (php &mysql)

Posted 01 April 2012 - 03:03 PM

Well, there are minor errors in the SQL that I can spot easily. There was no space separating the column name and the FROM keyword, and unless the check column is varchar, which I would say is unlikely, then the matching term should not be the string 'true'.

For starters, I would say try this:
<?php 	  
	include('con-db.php');
	$query = "SELECT coursename".
	" FROM selected_course".
	" WHERE selected_course.check = 1";
	$result = mysql_query($query) or die(mysql_error());
	while($r = mysql_fetch_array($result))
	{
	  echo"<tr><td><center>".$r['coursename']."</td></center</tr>";
	}
?>


But, that said, you really need to know what the datatype of the selectedcourse.check column is. Run this query to find out what the datatype type is:
SELECT data_type
FROM information_schema.columns
WHERE table_name = 'selected_course'
AND column_name = 'check'


If the datatype comes back as int, smallint, tinyint, bit or boolean, then true false values will be stored as 1 and 0.

Also, have you tried running your query directly against the DB in phpMyAdmin to see if any results actually get returned?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1