Jump to content


Photo

problem with foreach


  • Please log in to reply
4 replies to this topic

#1 iamq08

iamq08
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 19 July 2006 - 03:55 AM

I'm trying to populate a form in a menu for my website, and for some reason it won't pull the information from the database correctly. Any assistance would be real helpful.

here's the function from the include file

   function get_extensions(){
                $q = mysql_query("select name, context, mailbox, secret from extensions");
                while($info = mysql_fetch_array($q)){
                return $info;
                }
        }


Heres the excerpt from the php file
$vars = New Casename;
$vars->mysqldbcon();
$extens = $vars->get_extensions();
..............
................
<?
                foreach($extens as $val){
        ?>

<form action="user.php" method="POST">
                <tr bgcolor="#E7F3FB">
                      <td nowrap valign=top><input name="name" value="<?=$val['name']?>"></td>
                      <td nowrap valign=top><input type="text" maxlength="150" name="context" value="<?=$val['context']?>"></td>
                      <td nowrap valign=top><input type="text" maxlength="150" name="mailbox" value="<?=$val['mailbox']?>"></td>
                       <td nowrap valign=top><input type="text" maxlength="150" name="secret" value="<?=$val['secret']?>"></td>
                          <td nowrap valign=top><input type="Submit" name="action" value="Update"></td>
                      <td nowrap valign=top><input type="Submit" value="Remove" name="action"></td>
                </tr>
</form>
<?}?>

For some reason it doesn't pull the information correctly.

#2 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 19 July 2006 - 04:03 AM

what about the select statement

where id='$id' ";
Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#3 iamq08

iamq08
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 19 July 2006 - 04:26 AM

I'm trying to pull and populate the page with all of the entries, which is the reason for no where specification.  I don't think the problem is with the function, because I can print values, I think there may be somethin wrong with the foreach statement or below that.



#4 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 19 July 2006 - 04:33 AM


try a diffrent loop then ok

example.
<?
for($i=0; $i<count($extens); $i++){
?>

Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#5 akitchin

akitchin
  • Staff Alumni
  • Advanced Member
  • 2,516 posts
  • LocationCalgary, AB, Canada

Posted 19 July 2006 - 04:42 AM

try echoing the $extens and seeing if you actually have an array:

echo '<pre>'.print_r($extens, TRUE);

and if it's got the values you expect.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users