Need to add image to a databse

We crossed posts…

Anyway, that’s what i dod above and it does not work,

Or do I have to create a new column in the MySQL database for image?

Try the online Demo again.

I have added four images, one for each $chain.

If the ONLINE images do not show then refresh your browser using CTRL-F5

Once you see all four images then copy and paste the source code locally and ensure it works. Keep this as a template and add your database script in the currently REMMED section.

Edit:
I find it is far easier to get something simple to work then gradually add further enhancements such as database query results.

Ok, this is what it look like and the position where I put it. It does not work.

http://pintotours.net/TEMP/SPACE/test10.html Enter “Brussels”

Do I need to create a new column in the MySQK database for “image”?

$prepare->store_result(); // Store the results for later checking

// Use num_rows to check if the results return a 0 or 1. 0 meaning false and 1 meaning true
if($prepare->num_rows) {

$prepare->bind_result($chain, $country, $city, $top, $medium, $low); // Append variables to the columns you specified

function getImage($chain='NULL')
{
   $result = 'img_chain-default.jpg';

   switch ($chain) { 

case ‘accor’ : $result = ‘AccorTest.jpg’;
break;
case ‘hilton’ : $result = ‘HiltonTest.jpg’;
break;
case ‘IHG’ : $result = ‘IHGTest.jpg’;
break;
case ‘Melia’ : $result = ‘MeliaTest.jpg’;
break;

case ‘Marriott’ : $result = ‘MarriottTest.jpg’;
break;
}//endswitch

   return PATH_TO_IMAGES .$result;
}

// Throw them all in a while loop
while($prepare->fetch()) {

// Technically you don't need to use HEREDOCS because if you end the PHP tag and restart it
// You can have your full HTML in your PHP file
// This isn't ideal though, you should separate your HTML from PHP, but since you are still a beginner
// This doesn't really mean anything.
// I'd say put these results in a new PHP file and require it



 $img = getImage($chain);  
   $img = '<img src="'  .$img  .'" alt="" />';
  
?>

    <tr>
        <td> <?php echo $img; ?></td>
        <td> <?php echo $chain; ?></td>

Hi

Yes, I can see it but that is not what I need, I need to connect $Chains to indivdual images andthere may be as many as a dozen rows and they will all be different chains and therefore different images,

But John, the page is secondary. this is not a business:it’s a hobby and my main interest now is in understanding how all this works. It’s academic purely.

This is my first adventure in MySLQ, php, and Search scripts and I am hard trying to understand the one you sent me this morning. Until I do I will not ouch anything else. please help me with that first.

Thanks

@qim
Ok, this is what it look like and the position where I put it. It does not work.

Please read my previous post #22 that supplies an updated link to a working version complete with images related to your $chain.

Also as mentioned in a previous post the complete source code is available online.

Please copy and paste the source code to a local PHP Template file and ensure it is working.

Do not make any changes to the PHP Template. Make another copy and only make a single change, ensure it is working then move on to the next change.

But John, I need to finish the other code first…

Your original post was Need to add image to a database.

I have supplied a complete working demo of how to use a function to add an image to your MySql results. Four images relate to different $chains as you can see in the online demo.

If there are other problems please raise a new topic to avoid any confusion to this topic which is now [SOLVED].

John, you may have missed one of my comments above (I keep amending my posts and if you don’t go back to them you don’t get the full story)

spaceshiptrooper spent alot of time and effort helping me create the page that I am working on. I am very happy with it and would consider it disrespectful if I now put in the rubbish bin and adopted something else.

I must not, and I do not want to start on a new page, for that reason alone.

What I need, and came here because i did not want to bother spaceshiptrooper any further (for the time being…) is to add a thing or two to what I have. I do not want to change the page,

The code you sent me this morning seems to serve that purpose and I would like to persevere to see if I can make it work.

I understand your position, the time you took to help me, and regret that I have to write this, but I do it out of respect for other forum users.

I will not persist, but if you want to help me with the first code you sent, I will be grateful

Regards

Hi @qim
Yes, I can see it but that is not what I need, I need to connect
$Chains to indivdual images and there may be as many as a dozen rows and
they will all be different chains and therefore different images,

It is difficult for me to associate a dozen rows with the different $chains because I do not have your database or your images. All I can see is the rendered HTML

For the OUTPUT PAGE please include the function I supplied at the top of the Php page and replace the following:

// OLD SCRIPT

<td> 
   <?php echo $row['chain'];?> 
</td> 

// NEW SCRIPT ``` <?php echo getImage( $row['chain'] );?> ```

Edit:
If your output is using the object syntax then use the following:

   <?php echo  getImage( $row->chain );?> 

If it still does not render the images then please add the following script at the bottom of the Php page so that others can see the page contents:

<div style="width:88%; margin:2em auto; background-color:#fff; border:solid 1px red; padding:1em;">
  <b>SOURCE BOX: highlight text using mouse and copy and paste into a file.</b>
  <br />
  <?php highlight_file(__FILE__); ?>
</div>

<body>
</html>

Pleas note that it is rather late here and I am signing off for the day, hope you manage to render your images. I will check in tomorrow.

Have fun :slight_smile:

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.