Jump to content

Help with For each and array


jeff5656

Recommended Posts

Trying to get this to work but nothing gets displayed inside the if OR inside the else.  I am not sure what is $index and what is $value.

If index a field name that I selected, or is value a field name?

 

<?php
  $consultsq3 = "SELECT * FROM icu INNER JOIN family ON icu.id_incr = family.pt_id AND icu.id_incr = ' " . $row['id_incr'] . " '"; 

$result3 = mysql_fetch_assoc(mysql_query($consultsq3)) or die ("Invalid query: " . mysql_error ());

if (empty($result3))
{
   echo 'No record found!';

} else {

   foreach ($result3 as $index => $value)
   {
      echo "index is " .$index . "and vakue is". $value;
   }

Link to comment
https://forums.phpfreaks.com/topic/171290-help-with-for-each-and-array/
Share on other sites

try this:

 

<?php

$consultsq3 = mysql_query("SELECT * FROM icu INNER JOIN family ON icu.id_incr = family.pt_id AND icu.id_incr = ' " . $row['id_incr'] . " '") or die ("Invalid query: " . mysql_error ());
   
if (mysql_num_rows($consultsq3) == 0)
{
   echo 'No record found!';
}
else
{
    $result3 = mysql_fetch_assoc($consultq3);

    foreach ($result3 as $index => $value)
    {
        echo "index is " .$index . "and vakue is". $value;
    }
}

?>

I did what you outlined and I get this:

Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in C:\wamp\www\mc\test.php on line 204

 

I think the problem is I have no idea what "$index" AND "VAlue" are supposed to be.  Do both (or one) of them refer to a field name?  If so which one?  And then what does the other one represent?

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.