Jump to content

Displaying image and data from different tables

- - - - -

  • Please log in to reply
6 replies to this topic

#1
kirigwajoe

kirigwajoe

    Newbie

  • Members
  • Pip
  • 9 posts
I have a database "child" with tables "profile" and "jpg"

Table profile has column names; cnumb, cnam, cage, csex

Table jpg has column names; pid, cnam, imgdata.

I can display details from each table seperately but now i want to be able to display the image along with its details from another table.

Thank you.

File to display the profile details.

childfind.php

<html>

<body bgcolor=#afd1f4>

<legend>

<!-- <img src="umulogo.gif"><img src="index_header.gif"> -->

<table border='1' bgcolor=#7991d4 frame=lhs cellpadding="4" width=100%>

<tr bgcolor=#cbe0ac ><td><font face='Vinque'><B>SEARCH FOR A CHILD </B></TR>

<tr><td><p align="center"><font size="4" face="Vinque">

<form action="childfind.php" method="POST">

<p align="center"><font size="4" face="">

CHILD NAME:<br/>

<input  type="text"  name="cnam" size="30" /><br/>

<div align="center"><input type="submit" name="submit" value= "Find" />

<input type="reset" name="Clear" value= "Clear" />



</div>

</form>

<form action="child.html" method="POST">

<div align="left"><input type="submit" name="submit" value=" Back" />


<div  ALIGN="CENTER">

<blockquote>

  <p title="INSERT CHILD DETAILS" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0" width="100" height="22" accesskey="1">

    	<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0" width="100" height="22" accesskey="1" title="INSERT CHILD DETAILS">

      <param name="movie" value="CHILD.swf" />

      <param name="quality" value="high" />

      <embed src="CHILD.swf" quality="high" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="100" height="22" ></embed>

     </object>

    

    <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0" width="100" height="22" accesskey="2" title="UPDATE CHILD DETAILS">

      <param name="movie" value="CHILD1.swf" />

      <param name="quality" value="high" />

      <embed src="CHILD1.swf" quality="high" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="100" height="22" ></embed>

    </object>  

    

  

     <legend>

    <table border='1' bgcolor=d4ecfb frame=lhs cellpadding="4" width=100%>

  </p>

</blockquote>

<tr><td>

<title>Search Results</title></head><h4><p align="center"><font size="5"></font></h4></p>

<br/>




<?php

$cnumb=$_POST['cnumb'];

$cnam=$_POST['cnam'];

$ctribe=$_POST['ctribe'];

$cage=$_POST['cage'];

$cage=$_POST['cweight'];

$csex=$_POST['csex'];

$cclass=$_POST['cclass'];

$resident=$_POST['resident'];

$pnam=$_POST['pnam'];

$ploc=$_POST['ploc'];

$cpnumb=$_POST['cpnumb'];

$foccupation=$_POST['foccupation'];

$mnam=$_POST['mnam'];

$mloc=$_POST['mloc'];

$mpnumb=$_POST['mpnumb'];

$moccupation=$_POST['moccupation'];

$cloc=$_POST['cloc'];

$category=$_POST['category'];

$cnationality=$_POST['cnationality'];

$crelatives=$_POST['crelatives'];

$brosis=$_POST['brosis'];

$cdisabilty=$_POST['cdisabilty'];

$ccarrier=$_POST['ccarrier'];

$creligion=$_POST['creligion'];

$parostatus=$_POST['parostatus'];

$cdatedel=$_POST['cdatedel'];




$server = 'localhost';

$dbuser="root";

$dbpasswd="";

// Make a MySQL Connection

mysql_connect($server , $dbuser , $dbpasswd) or die(mysql_error());

mysql_select_db("child") or die(mysql_error());


// Get all the data from the "profile" table

$select=mysql_query("select * from `profile` where cnam='$cnam'");

//$result=mysql_query($select);


echo " <P ALIGN='CENTER'><b>$cnam'S    DETAILS   FROM   M-LISADA   DATABASE  ";


while($info=mysql_fetch_array($select)){

echo '


<table align="center" border="0" cellspacing="0" cellpadding="0"  bgcolor=c6c7c9  style="border-style:dashed; border-width:1px; border-color:#6b5d3f;" >

<form method=post action=childupdate1.php>

<tr><td>CHILD NUMBER</td><td>

<input name="cnumb" class="textfield" value="'.$info[cnumb].'">

</td></tr>


<tr><td>CHILD NAME</td><td>

<input name="cnam" class="textfield" value="'.$info[cnam].'" size=30 class="textfield">

</td></tr>



<tr><td>CHILD TRIBE</td><td>

<input name="ctribe" class="textfield" value="'.$info[ctribe].'" size=30 class="textfield">

</td></tr>



<tr><td>CHILD AGE</td><td>

<input type=text name=cage value="'.$info[cage].'" size=30 class="textfield"></td></tr>


<tr><td>CHILD WEIGHT</td><td>

<input type=text name=cweight value="'.$info[cweight].'" size=30 class="textfield"></td></tr>



<tr><td>CHILD SEX</td><td>

<input type=text name=csex value="'.$info[csex].'" size=30 class="textfield"></td></tr>




<tr><td>CLASS</td><td>

<input type=text name="cclass" class="textfield" value="'.$info[cclass].'">

</td></tr>


<tr><td>RESIDENT</td><td>

<input type=text name="resident" class="textfield" value="'.$info[resident].'">

</td></tr>


<tr><td>FATHERS NAME </td><td>

<input type=text name="pnam" class="textfield" value="'.$info[pnam].'" size=30 class="textfield">

</td></tr>


<tr><td>FATHERS PHONE NUMBER</td><td>

<input type=text name=cpnumb value="'.$info[cpnumb].'" </td></tr>


<tr><td>FATHERS OCCUPATION</td><td>

<input type=text name=foccupation value="'.$info[foccupation].'" size=30 class="textfield"></td></tr>


<tr><td>FATHERS LOCATION</td><td>

<input type=text name="ploc" class="textfield" value="'.$info[ploc].'">

</td></tr>


<tr><td>MOTHERS NAME</td><td>

<input type=text name=mnam value="'.$info[mnam].'" size=30 class="textfield"></td></tr>


<tr><td>MOTHERS LOCATION</td><td>

<input type=text name=mloc value="'.$info[mloc].'" size=30 class="textfield"></td></tr>


<tr><td>MOTHERS PHONE NUMBER</td><td>

<input type=text name=mpnumb value="'.$info[mpnumb].'" size=30 class="textfield"></td></tr>


<tr><td>MOTHERS OCCUPATION</td><td>

<input type=text name=moccupation value="'.$info[moccupation].'" size=30 class="textfield"></td></tr>


<tr><td>WHERE M-LISADA FOUND YOU</td><td>

<input type=text name=cloc value="'.$info[cloc].'" class="textfield">

</td></tr>


<tr><td>CATEGORY</td><td>

<input type=text name="category" class="textfield" value="'.$info[category].'">

</td></tr>


<tr><td>NATIONALITY</td><td>

<input type=text name="cnationality" class="textfield" value="'.$info[cnationality].'">

</td></tr>


<tr><td>NAMES OF BROTHERS/SISTERS</td><td>

<input type=text name="brosis" class="textfield" value="'.$info[brosis].'" size=60 >

</td></tr>


<tr><td>RELATIVES</td><td>

<input type=text name="crelatives" class="textfield" value="'.$info[crelatives].'" size=60 >

</td></tr>


<tr><td>DISABILITY</td><td>

<input type=text name="cdisabilty" class="textfield" value="'.$info[cdisabilty].'">

</td></tr>


<tr><td>FUTURE CARRIER</td><td>

<input type=text name="ccarrier" class="textfield" value="'.$info[ccarrier].'">

</td></tr>


<tr><td>RELIGION</td><td>

<input type=text name="creligion" class="textfield" value="'.$info[creligion].'">

</td></tr>


<tr><td>PARENT LIVING</td><td>

<input type=text name="parostatus" class="textfield" value="'.$info[parostatus].'">

</td></tr>


<tr><td>ARRIVAL DATE</td><td>

<input type=text name="cdatedel" class="textfield" value="'.$info[cdatedel].'">

</td></tr>


</form>


</table>';

}


?>

</legend>

</body></html>





#2
ghost_x47

ghost_x47

    Learning Programmer

  • Members
  • PipPipPip
  • 45 posts
Try to use join if i understand correctly - this should work
$sql = "SELECT * FROM `profile` LEFT JOIN `jpg` ON `jpg`.`cnam` = `profile`.`cnam` WHERE `profile`.`cnam`='$cnam'";


#3
kirigwajoe

kirigwajoe

    Newbie

  • Members
  • Pip
  • 9 posts
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\wamp\www\CHILD\childfind.php on line 80

is the warning dispalyed in the browser.

it does not display anything from the tables.

#4
ghost_x47

ghost_x47

    Learning Programmer

  • Members
  • PipPipPip
  • 45 posts
you should check what you get from sql query.
1. echo your final query
2. enter it in phpmyadmin or basic mysql cli.
3. maybe try to EXPLAIN query.
post all of that here, if you still don't know the problem.

#5
kirigwajoe

kirigwajoe

    Newbie

  • Members
  • Pip
  • 9 posts
I have two tables and the table jpg contains images.

Anyway let me send you the whole code s it looks now and you do with it what you think is right.

thanks but i did not understand what u referred to in previous post.

please keep in touch

code for childfind.php

<html>

<body bgcolor=#afd1f4>

<legend>


<table border='1' bgcolor=#7991d4 frame=lhs cellpadding="4" width=100%>

<tr bgcolor=#cbe0ac ><td><font face='Vinque'><B>SEARCH FOR A CHILD </B></TR>

<tr><td><p align="center"><font size="4" face="Vinque">


<form action="childfind.php" method="POST">


<p align="center"><font size="4" face="">

CHILD NAME:<br/>

<input  type="text"  name="cnam" size="30" /><br/>

<div align="center"><input type="submit" name="submit" value= "Find" />

<input type="reset" name="Clear" value= "Clear" />



</div>

</form>

<form action="child.html" method="POST">

<div align="left"><input type="submit" name="submit" value=" Back" />


<div  ALIGN="CENTER">

<blockquote>

  <p title="INSERT CHILD DETAILS" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0" width="100" height="22" accesskey="1">

    	<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0" width="100" height="22" accesskey="1" title="INSERT CHILD DETAILS">

      <param name="movie" value="CHILD.swf" />

      <param name="quality" value="high" />

      <embed src="CHILD.swf" quality="high" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="100" height="22" ></embed>

     </object>

    

    <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0" width="100" height="22" accesskey="2" title="UPDATE CHILD DETAILS">

      <param name="movie" value="CHILD1.swf" />

      <param name="quality" value="high" />

      <embed src="CHILD1.swf" quality="high" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="100" height="22" ></embed>

    </object>  

    

  

     <legend>

    <table border='1' bgcolor=d4ecfb frame=lhs cellpadding="4" width=100%>

  </p>

</blockquote>

<tr><td>

<title>Search Results</title></head><h4><p align="center"><font size="5"></font></h4></p>

<br/>




<?php

//assigning variables


$cnumb=$_POST['cnumb'];

$cnam=$_POST['cnam'];





$server = 'localhost';

$dbuser="root";

$dbpasswd="";

// Make a MySQL Connection

mysql_connect($server , $dbuser , $dbpasswd) or die(mysql_error());

mysql_select_db("child") or die(mysql_error());


// Get all the data from the "profile" table

//$select=mysql_query("select * from `profile` where cnam='$cnam'");

//$result=mysql_query($select);


// Get all the data from the "profile" and image from jpg  table

//$query = "SELECT `profile`.*, `jpg`.`imgdata`

//FROM `child`.`profile`, `child`.`jpg`

//WHERE `profile`.`cnam` = '".$_POST['cnam']."'

//AND `profile`.`cnam` = `jpg`.`cnam`";



$sql = "SELECT * FROM `profile` LEFT JOIN `jpg` ON `jpg`.`cnam` = `profile`.`cnam` WHERE `profile`.`cnam`='$cnam'";  



$select=mysql_query($query); 




echo " <P ALIGN='CENTER'><b>$cnam'S    DETAILS   FROM   M-LISADA   DATABASE  ";


while($info=mysql_fetch_array($select)){

echo '


<table align="center" border="0" cellspacing="0" cellpadding="0"  bgcolor=c6c7c9  style="border-style:dashed; border-width:1px; border-color:#6b5d3f;" >

<form method=post action=childupdate1.php>

<tr><td>CHILD NUMBER</td><td>

<input name="cnumb" class="textfield" value="'.$info['cnumb'].'">

</td></tr>


<tr><td>CHILD NAME</td><td>

<input name="cnam" class="textfield" value="'.$info['cnam'].'" size=30 class="textfield">

</td></tr>



<tr><td>CHILD TRIBE</td><td>

<input name="ctribe" class="textfield" value="'.$info['ctribe'].'" size=30 class="textfield">

</td></tr>



<tr><td>CHILD AGE</td><td>

<input type=text name=cage value="'.$info['cage'].'" size=30 class="textfield"></td></tr>


<tr><td>CHILD WEIGHT</td><td>

<input type=text name=cweight value="'.$info['cweight'].'" size=30 class="textfield"></td></tr>



<tr><td>CHILD SEX</td><td>

<input type=text name=csex value="'.$info['csex'].'" size=30 class="textfield"></td></tr>




<tr><td>CLASS</td><td>

<input type=text name="cclass" class="textfield" value="'.$info['cclass'].'">

</td></tr>


<tr><td>RESIDENT</td><td>

<input type=text name="resident" class="textfield" value="'.$info['resident'].'">

</td></tr>


<tr><td>FATHERS NAME </td><td>

<input type=text name="pnam" class="textfield" value="'.$info['pnam'].'" size=30 class="textfield">

</td></tr>


<tr><td>FATHERS PHONE NUMBER</td><td>

<input type=text name=cpnumb value="'.$info['cpnumb'].'" </td></tr>


<tr><td>FATHERS OCCUPATION</td><td>

<input type=text name=foccupation value="'.$info['foccupation'].'" size=30 class="textfield"></td></tr>


<tr><td>FATHERS LOCATION</td><td>

<input type=text name="ploc" class="textfield" value="'.$info['ploc'].'">

</td></tr>


<tr><td>MOTHERS NAME</td><td>

<input type=text name=mnam value="'.$info['mnam'].'" size=30 class="textfield"></td></tr>


<tr><td>MOTHERS LOCATION</td><td>

<input type=text name=mloc value="'.$info['mloc'].'" size=30 class="textfield"></td></tr>


<tr><td>MOTHERS PHONE NUMBER</td><td>

<input type=text name=mpnumb value="'.$info['mpnumb'].'" size=30 class="textfield"></td></tr>


<tr><td>MOTHERS OCCUPATION</td><td>

<input type=text name=moccupation value="'.$info['moccupation'].'" size=30 class="textfield"></td></tr>


<tr><td>WHERE M-LISADA FOUND YOU</td><td>

<input type=text name=cloc value="'.$info['cloc'].'" class="textfield">

</td></tr>


<tr><td>CATEGORY</td><td>

<input type=text name="category" class="textfield" value="'.$info['category'].'">

</td></tr>


<tr><td>NATIONALITY</td><td>

<input type=text name="cnationality" class="textfield" value="'.$info['cnationality'].'">

</td></tr>


<tr><td>NAMES OF BROTHERS/SISTERS</td><td>

<input type=text name="brosis" class="textfield" value="'.$info['brosis'].'" size=60 >

</td></tr>


<tr><td>RELATIVES</td><td>

<input type=text name="crelatives" class="textfield" value="'.$info['crelatives'].'" size=60 >

</td></tr>


<tr><td>DISABILITY</td><td>

<input type=text name="cdisabilty" class="textfield" value="'.$info['cdisabilty'].'">

</td></tr>


<tr><td>FUTURE CARRIER</td><td>

<input type=text name="ccarrier" class="textfield" value="'.$info['ccarrier'].'">

</td></tr>


<tr><td>RELIGION</td><td>

<input type=text name="creligion" class="textfield" value="'.$info['creligion'].'">

</td></tr>


<tr><td>PARENT LIVING</td><td>

<input type=text name="parostatus" class="textfield" value="'.$info['parostatus'].'">

</td></tr>


<tr><td>ARRIVAL DATE</td><td>

<input type=text name="cdatedel" class="textfield" value="'.$info['cdatedel'].'">

</td></tr>


<tr><td>JPG</td><td>

<img src="'.$info['imgdata'].'" alt="My Alt Text" />

</td></tr> 


</form>


</table>';

}


?>

</legend>

</body></html>





#6
John

John

    Writes binary right handed and hex left handed

  • Moderators
  • 6,321 posts
  • Location:New York, NY
Debugging MySQL issues in PHP | John Ciacia

#7
ghost_x47

ghost_x47

    Learning Programmer

  • Members
  • PipPipPip
  • 45 posts
Of course you have empty result. I write answer just an example.
You actually need to get $sql variable to mysql_query function,
in your script you are using a variable $query, but i didn't see where you defined it.
you need to send query in $sql variable, like this

$sql = "SELECT * FROM `profile` LEFT JOIN `jpg` ON `jpg`.`cnam` = `profile`.`cnam` WHERE `profile`.`cnam`='$cnam'";   //generating a query

$select=mysql_query($sql);  //send query to mysql






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users