Page 1 of 1

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

Posted: Mon Jan 16, 2006 9:23 am
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?

Posted: Mon Jan 16, 2006 9:25 am
by Weirdan
array elements are accessed using square brackets ([]):

Code: Select all

echo $mealresults['Meal_ID'];

Posted: Mon Jan 16, 2006 9:28 am
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.

Posted: Mon Jan 16, 2006 9:46 am
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;
			}
                 }

Posted: Mon Jan 16, 2006 9:59 am
by Weirdan
err... there's no single echo() in the code you've posted

Posted: Mon Jan 16, 2006 10:10 am
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>";		 
		 ?>

Posted: Mon Jan 16, 2006 10:20 am
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