Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > Pro PHP
|
Pro PHP Advanced PHP coding discussions. Beginning-level questions will be redirected to the Beginning PHP forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Pro PHP section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 22nd, 2004, 09:10 PM
Registered User
 
Join Date: Jun 2004
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to samergamer
Default Problem with foreach when using linking

I am trying to use the command foreach to create a drop down menu. That I can usually do, the problem is I am also adding some linking. Here is some my code:
<?sql

$sql2 = "SELECT mn.map, mn.route FROM maps m JOIN map_name mn ON (m.map_name = mn.map) WHERE `ship`='".$POST['ship']."'";
$result2 = mysql_query($sql2)
    or die("Query Error".mysql_error());
    while ($row = mysql_fetch_array($result2)) {
    $mapname[$row['mn.map']] = $row['mn.route'];
}
    ?>

<form action="edit_map_which.php" method="post">
<table border=0 cellspacing=1>
<tr>
<td>
Map :
</td>
<td>
<SELECT name="map">
<option value="" SELECTED>Select a Map</option>
<?php
foreach( $mapname as $map => $route ){ **
?>
<option value="<?php echo $map ?>"><?php echo $route ?></option>
<?php }
?>
</SELECT>
</td>
</tr>
<tr>
<td>
<INPUT type="submit" name="Submit" value="Submit">
</td>
</tr>
</table>

** I get the error Invalid argument supplied for foreach() for this line.

I've tried quite a few different things for this, and I now feel like I am beating my head against the wall. Thanks for the help.

 
Old June 24th, 2004, 05:32 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 256
Thanks: 0
Thanked 0 Times in 0 Posts
Default

"Invalid argument supplied for foreach()" indicates that your '$mapname' is not an array, which in turn implies that your SELECT is returning with an empty set. Have you tried echoing your SELECT statement and running it against your database to see what happens?

Take it easy,
Dan
Will-code-PHP-for-Athlons-and-powerbooks
"If Darl McBride was in charge, he'd probably make marriage unconstitutional too,
since clearly it de-emphasizes the commercial nature of normal human interaction, and
is a major impediment to the commercial growth of prostitution."





Similar Threads
Thread Thread Starter Forum Replies Last Post
Subform linking problem JimTate BOOK: Access 2007 VBA Programmer's Reference ISBN: 978-0-470-04703-3 0 April 22nd, 2008 11:07 AM
foreach confusion stokerfed C# 2 June 13th, 2007 02:30 PM
Linking Problem glisando Dreamweaver (all versions) 1 September 15th, 2006 07:25 AM
Problem with linking images in crystal reports gpdhillon Crystal Reports 6 September 6th, 2006 11:06 PM
problem with foreach loop in Checkboxes datagrid mbge9pjb .NET Framework 2.0 2 December 20th, 2005 10:03 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.