Fire Juggler wrote:
Hi I have this this code
{while ($row = mysql_fetch_array($numresultsgal)) {
$table=$row{'table_gal'};
$numresultphotos=mysql_query("SELECT * FROM" .$table. "order by date
desc"); $numphotos=mysql_num_rows($numresultphotos);
echo"<b>Gallery:</b> " .$row{'gallery'}. "<br>";
echo "<b>No. Of Photos:</b> " .$numphotos. "<br>" ;}
But it keeps failing to produce the number of photos in the gallery.
But it will display the table name if i want it to. So it's got the
correct name, so any ideas why it's failing and not telling me how
many rows are in the database.
Is that the EXACT code? If so, you have an error in your SQL syntax. That
error is resulting in a false value for $numresultphotos, which, in turn,
gives a false value for $numphotos.
The error that I see is in the lack of spaces: "SELECT * FROM" . $table .
"order by date desc" - if $table = 'MyTable', your query would be "SELECT *
FROMMyTableorder by date desc" - add spaces: ".. FROM " . $table . " order
by..."
If you also add some error reporting, you'll probably find errors faster -
and, BTW, you don't have to concatenate variables when using double-quotes:
$numresultphotos = mysql_query("SELECT * FROM $table order by date desc");
if (!$numresultphotos) { die (mysql_error()); }
$numphotos = mysql_num_rows($numresultphotos);
--
Tony Garcia
Web Right! Development
Riverside, CA
www.WebRightDevelopment.com