Web Hosting Talk







View Full Version : PHP Help


FXWeb
11-26-2002, 06:26 PM
I am trying to post data from a database (mysql)

<?php

$dbh=mysql_connect ("localhost", "fxhost_admin", "**********") or die ('I cannot connect to the database.');
mysql_select_db ("fxhost_cycle");

$sql = 'SELECT * FROM `data` LIMIT 0, 100';

?>

what am I missing?

Jeff

JWM1173 - AIM

beowulfdk
11-26-2002, 06:41 PM
>>$sql = 'SELECT * FROM `data` LIMIT 0, 100';

I'm not sure you should use 's around data, atleast I wouldnt. Guess it might work either way.

Except from that I'ed say ok if you are trying to fetch some data from the database, you do no such thing. You only assign a string containing your query to a variable. You might wanna do this:

$qresult=mysql_query($sql);

And then get data from $qresult. An example from something I am using:

$main.="<td align=\"center\"><b>URL</b></td><td align=\"center\"><b>Title</b></td></tr>";
$tld=mysql_query("SELECT host,title FROM redir WHERE cat = '$cat' ORDER BY lasttime DESC LIMIT 0,30") or die (mysql_error());
while($tld_array=mysql_fetch_array($tld)) {
$host=$tld_array[0];
$title=$tld_array[1];
$main.="<tr><td align=\"center\"><a href=\"http://$host/\" target=\"_blank\">http://$host/</a></td><td align=\"center\">$title</td></tr>";
}
$main.="</table>";


Edit: oh hehe I only just noticed. USe "s not 's to define a string :)

$sql = "SELECT * FROM `data` LIMIT 0, 100";