help php

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
forgun
Forum Commoner
Posts: 61
Joined: Wed Jan 29, 2003 6:05 am
Contact:

help php

Post 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&#1111;"id"],$row&#1111;"title"]);
&#125;
it's isnt give my any out put form the db why?
bionicdonkey
Forum Contributor
Posts: 132
Joined: Fri Jan 31, 2003 2:28 am
Location: Sydney, Australia
Contact:

Post by bionicdonkey »

the problem is in $qur...'WHERE 1'...there needs to be an condition e.g. 'WHERE rowname=1'
User avatar
forgun
Forum Commoner
Posts: 61
Joined: Wed Jan 29, 2003 6:05 am
Contact:

Post 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)) &#123;
	$id = $row&#1111;"id"];
	$tit = $row&#1111;"title"];
&#125;
part two

Code: Select all

for ($i = 0 ;$i <= 4 ; $i++) &#123;
	if ($tit) &#123;
		echo  "<option value="N/A"> N/A </option>";
	&#125;
	echo "<option value="" $id "">" $tit "</option>"; #the error line
&#125;

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
evilcoder
Forum Contributor
Posts: 345
Joined: Tue Dec 17, 2002 5:37 am
Location: Sydney, Australia

Post 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>";
bionicdonkey
Forum Contributor
Posts: 132
Joined: Fri Jan 31, 2003 2:28 am
Location: Sydney, Australia
Contact:

Post by bionicdonkey »

replace:
$res = mysql_query($res) or die (mysql_error());
with
$res = mysql_query($qur) or die (mysql_error());
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post 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
User avatar
forgun
Forum Commoner
Posts: 61
Joined: Wed Jan 29, 2003 6:05 am
Contact:

Post 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";
?>
Post Reply