[SOLVED] stupid graphics made me rusty... syntax question

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
$var
Forum Contributor
Posts: 317
Joined: Thu Aug 18, 2005 8:30 pm
Location: Toronto

[SOLVED] stupid graphics made me rusty... syntax question

Post by $var »

does this immediately look wrong?

Code: Select all

$sql2 = "SELECT * FROM meals WHERE Meal_CID =".$memcity;
	  	$result = mysql_query($sql2) or die (mysql_error());
	        $mealresults = mysql_fetch_array($result);
		echo "$memcity";
		echo "$mealresults('Meal_ID')";
		$mealid = $mealresults('Meal_ID');

Echoing out the $memcity variable is good
Echoing out the $sql2 is fine

However, when I want to echo the Meal_ID, it's only pulling the term 'Meal_ID'

What'd I do?
Last edited by $var on Mon Jan 16, 2006 10:36 am, edited 1 time in total.
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post by Weirdan »

array elements are accessed using square brackets ([]):

Code: Select all

echo $mealresults['Meal_ID'];
User avatar
$var
Forum Contributor
Posts: 317
Joined: Thu Aug 18, 2005 8:30 pm
Location: Toronto

Post by $var »

heh heh... right.

i hate working on stupid graphics.
they don't make data flow well in my brain.

thank so much.
back on track.
User avatar
$var
Forum Contributor
Posts: 317
Joined: Thu Aug 18, 2005 8:30 pm
Location: Toronto

Post by $var »

Okay, so that is one problem solved
(i'm literally hanging my head with my lost abilities... i have a solid month to program again though, yay)

K, so this peice is doing almost everything right:

- selecting the count (which is 3 fields)
- echoing all the fields

- however, it's echoing the first field in the table 3 times?

Code: Select all

$sql2 = "SELECT COUNT(*) FROM meals WHERE Meal_CID =".$memcity;
		$numrecord = mysql_query($sql2);
		$numrecords = mysql_fetch_array($numrecord);
		
		$intRecsPerPage=5;
		if($_POST["intpage"]=="")
		{
			$intpage=1;
		}
	  
	        $sql2 = "SELECT * FROM meals WHERE Meal_CID = $memcity";
	  	$result = mysql_query($sql2) or die (mysql_error());
  	        $mealresults = mysql_fetch_array($result);
		
                $mealid = $mealresults['Meal_ID'];
		$mealttl = $mealresults['Meal_Title'];
		$mealdesc = $mealresults['Meal_Desc'];	
		for($x = (($intpage-1) * $intRecsPerPage); $x < (($intpage-1) * $intRecsPerPage) + $intRecsPerPage; $x++)
		{
			if($x >= $numrecords[0])
			{
				break;
			}
                 }
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post by Weirdan »

err... there's no single echo() in the code you've posted
User avatar
$var
Forum Contributor
Posts: 317
Joined: Thu Aug 18, 2005 8:30 pm
Location: Toronto

Post by $var »

yah... sorry about that:

Code: Select all

<? 
		$sql2 = "SELECT COUNT(*) FROM meals WHERE Meal_CID =".$memcity;
		$numrecord = mysql_query($sql2);
		$numrecords = mysql_fetch_array($numrecord);
		
		$intRecsPerPage=5;
		if($_POST["intpage"]=="")
		{
			$intpage=1;
		}
	  
	  $sql2 = "SELECT * FROM meals WHERE Meal_CID = $memcity";
	  	$result = mysql_query($sql2) or die (mysql_error());
	    $mealresults = mysql_fetch_array($result);
		$mealid = $mealresults['Meal_ID'];
		$mealcity = $mealresults['Meal_CID'];
		$mealttl = $mealresults['Meal_Title'];
		$mealdesc = $mealresults['Meal_Desc'];	
		echo "<table width='100%' border='0' cellspacing='2' cellpadding='2'>";

		for($x = (($intpage-1) * $intRecsPerPage); $x < (($intpage-1) * $intRecsPerPage) + $intRecsPerPage; $x++)
		{
			if($x >= $numrecords[0])
			{
				break;
			}

		 echo "<tr bgcolor='#FFFFFF' class='text' background='../../images/_3_17.gif'>";
		 echo "<td valign='top' class='text' align='right' width='178'><b>Breakfast Meal :</b></td>";
		 echo "<td valign='top' class='text'><input name='breakfast' type='radio' value='$mealid'></td>";
		 echo "<td valign='top' class='text'><b>$mealttl</b><br>$mealdesc</td>";		 		 
		 echo "</tr>";
		 }
		 echo "</table>";		 
		 ?>
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Post by Weirdan »

put this part:

Code: Select all

$mealresults = mysql_fetch_array($result);
        $mealid = $mealresults['Meal_ID'];
        $mealcity = $mealresults['Meal_CID'];
        $mealttl = $mealresults['Meal_Title'];
        $mealdesc = $mealresults['Meal_Desc'];
into the loop body
Post Reply