Jump to content

Slideshow from database mysql/php


takisis

Recommended Posts

I am trying to display a slideshow using images and text from a database.

 

Here is my php code to get images and text from database:

 

<?php
            $dbhost = 'localhost';
            $dbuser = 'takisis';
            $dbpass = 'zifnab#666';
            $conn = mysql_connect($dbhost, $dbuser, $dbpass);
            if(! $conn )
            {
              die('Could not connect: ' . mysql_error());
            }
            $query=mysql_query("SELECT * FROM vehicles");
            echo 'ss = new slideshow("ss");';
            while ($row=mysql_fetch_assoc($query)) { ?>
            s = new slide();
            s.src =  "<?php echo "<img src='data:image/jpeg;base64,".base64_encode($row['image'])."'?>";
            s.text = "<?php echo "($row['year'] . $row['make'] . $row['model'] . $row['price'])"; ?>";
            ss.add_slide(s);
            }
            ?>

 

Please help

Link to comment
Share on other sites

sorry if this sounds too blunt, but you cannot program if you aren't looking at and learning what the statements in the code are doing.

 

in your previous thread, you were selecting a database. in this code you are not. you cannot run a database query query unless you select a database or explicitly list the database name in the query.

 

in your previous thread someone suggest setting php's error_reporting/display_errors settings, adding error checking logic to your database queries, and testing if queries match any rows. where is your code that's doing these things? if you always do these things, php and your code will tell you when something fails, where is it failing at, and why, or at least where to start looking to find out why it failed.

 

you also should not be trying to use the mysql_ statements. they are obsolete and will be removed from php in the future. what you are learning now will be out of date and the code you are writing will stop working and need to be rewritten. you had mysqli_ statements in your last thread. you should have corrected that code to use ALL mysqli_ statements.

Link to comment
Share on other sites

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.