Jump to content

selecting from tables


peuge

Recommended Posts

Hi,

I am selecting everything from a table and now I want to display it all. The only problem is that each thing comes as an element of the array $row. If I echo $row[1], $row[2] then I get what I want but is there an easier way? Am I using the wrong fetch command?

Thanks.

 

$result = mysql_query("SELECT * FROM $tables[0]");

 

 

while($row = mysql_fetch_array($result))

{

 

  echo "<tr>";

  echo "<td>" . $row[0] . "</td>";

  echo "</tr>";

}

 

Link to comment
https://forums.phpfreaks.com/topic/97968-selecting-from-tables/
Share on other sites

Sorry I was not quite clear in my first post. I am creating something along the lines of the user selects a database of his/her choice and then it displays the data for that database. Therefore using 'firstname' might apply to a table in one database but not the other. So is there another way?

Thanks

Link to comment
https://forums.phpfreaks.com/topic/97968-selecting-from-tables/#findComment-501251
Share on other sites

the examples i put are just that, examples, change the words inside the brackets to what column names you have in your database

 

this makes it easier for me because i know what column names I am pulling from the database so the I can use the column names and not the array key makes my life more interesting

Link to comment
https://forums.phpfreaks.com/topic/97968-selecting-from-tables/#findComment-501253
Share on other sites

Paul2463: Thanks. But the code still does not help because I have different tables in different databases with different heading names as well as the tables have a different number of fields.

 

Thorpe: It seems to be giving me duplicates as well as not putting them next to each other in the table? Sorry im quite new to this.

 

Thanks

Link to comment
https://forums.phpfreaks.com/topic/97968-selecting-from-tables/#findComment-501261
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.