Jump to content

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?

 

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.