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
$var
Forum Contributor
Posts: 317 Joined: Thu Aug 18, 2005 8:30 pm
Location: Toronto
Post
by $var » Mon Jan 16, 2006 9:23 am
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.
Weirdan
Moderator
Posts: 5978 Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine
Post
by Weirdan » Mon Jan 16, 2006 9:25 am
array elements are accessed using square brackets ([]):
$var
Forum Contributor
Posts: 317 Joined: Thu Aug 18, 2005 8:30 pm
Location: Toronto
Post
by $var » Mon Jan 16, 2006 9:28 am
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.
$var
Forum Contributor
Posts: 317 Joined: Thu Aug 18, 2005 8:30 pm
Location: Toronto
Post
by $var » Mon Jan 16, 2006 9:46 am
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;
}
}
Weirdan
Moderator
Posts: 5978 Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine
Post
by Weirdan » Mon Jan 16, 2006 9:59 am
err... there's no single
echo() in the code you've posted
$var
Forum Contributor
Posts: 317 Joined: Thu Aug 18, 2005 8:30 pm
Location: Toronto
Post
by $var » Mon Jan 16, 2006 10:10 am
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>";
?>
Weirdan
Moderator
Posts: 5978 Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine
Post
by Weirdan » Mon Jan 16, 2006 10:20 am
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