Page 1 of 1
help php
Posted: Fri Jan 31, 2003 2:06 am
by forgun
Code: Select all
@$lk = mysql_connect($serv,$user,$pass) or die (mysql_error());
$db = mysql_select_db($dbname,$lk);
$qur = "select * from news where 1 order by id desc limit 4";
$res = mysql_query($res,$lk) or die (mysql_error());
while ($row = mysql_fetch_assoc($res)) {
printf("<option value="%s">%s</option>",$rowї"id"],$rowї"title"]);
}
it's isnt give my any out put form the db why?
Posted: Fri Jan 31, 2003 2:28 am
by bionicdonkey
the problem is in $qur...'WHERE 1'...there needs to be an condition e.g. 'WHERE rowname=1'
Posted: Fri Jan 31, 2003 3:05 am
by forgun
here the fix one still not working
part one
Code: Select all
@$lk = mysql_connect($serv,$user,$pass) or die (mysql_error());
$db = mysql_select_db($dbname,$lk);
$qur = "select * from news order by id desc limit 4";
$res = mysql_query($res) or die (mysql_error());
while ($row = mysql_fetch_array($res,MYSQL_ASSOC)) {
$id = $rowї"id"];
$tit = $rowї"title"];
}
part two
Code: Select all
for ($i = 0 ;$i <= 4 ; $i++) {
if ($tit) {
echo "<option value="N/A"> N/A </option>";
}
echo "<option value="" $id "">" $tit "</option>"; #the error line
}
Code: Select all
Parse error: parse error, unexpected T_VARIABLE, expecting ',' or ';' in /home/virtual/site13/fst/var/www/html/staff/upchng.php on line 36
plz help i dont know what is the error is about and how to fix
Posted: Fri Jan 31, 2003 3:12 am
by evilcoder
echo "<option value=\"$id\">$tit</option>";
should work, butif you want to do it your way, do it like this:
echo "<option value=\"" . $id . "\">" . $tit . "</option>";
Posted: Fri Jan 31, 2003 3:20 am
by bionicdonkey
replace:
$res = mysql_query($res) or die (mysql_error());
with
$res = mysql_query($qur) or die (mysql_error());
Posted: Fri Jan 31, 2003 3:41 am
by twigletmac
You could simplify this (including adding the fix that evilcoder already pointed out):
Code: Select all
echo "<option value="" $id "">" $tit "</option>"; #the error line
to
Code: Select all
echo '<option value="'.$id.'">'.$tit.'</option>';
Then you don't have to worry about escaping the double quotes.
Mac
Posted: Fri Jan 31, 2003 5:41 am
by forgun
i have a prob that in the id exp: id = 1
is show me in the option only what is on the id 2 not 3,4,5 and 6
why is that
Code: Select all
<?php
$qur = "select * from news order by id desc limit 4";
?>