Could someone point me in the right direction for a tutorial, I've been looking for ajax tutorials that pass MySQL query answers through to another url.
What I'm trying to produce is a database that lists EP information, track title, artist name that sort of thing. But the important thing is the EP artwork which I have stored as a VARCHAR url within the database as "picture_url".
I want the pictures all to print into one <div>
so that once they are clicked the EP information as well as a larger image is loaded into the <div id= "epinfo">
What I've done is set the images ID to the databases auto incremented releases_id
. This way I can make my SQL:
SELECT * FROM releases WHERE releases_id = //image id
I have tried turning this into a variable to send through ajax but I can not seem to place the variable, if it's before the $j
it won't work as $j
is part of the variable. To place it after interrupts the echo function. Am I right in saying that $j
is not a global variable? If so could this be the problem as I have tried to change this but failed?
Is their a tutorial that is a little more specific in this kind of ajax request?
I'm new to PHP and Ajax programming so any help would be greatly appreciated.
Here is my php code:
<div id="epcovers">
<?php
require_once 'arcko_admin.php';
$db_server = mysql_connect($db_hostname, $db_username, $db_password);
if(!$db_server) die("unable to connect to mysql:" . mysql_error());
mysql_select_db($db_database)
or die("Unable to select database: " . mysql_error());
$query = "SELECT * FROM releases";
$result = mysql_query($query);
if(!$result) die ("Database access failed: " .mysql_error());
$rows = mysql_num_rows($result);
for($j = 0 ; $j < $rows ; ++$j)
{
echo '<img src="' . mysql_result($result,$j,'picture_url') . '" class= "ep" id= "' . mysql_result($result,$j,'release_id'). ' " width= "200" height= "200"/>';
}
mysql_close($db_server);
?>
<div id="epinfo">
<?php
echo //track title, artist information, etc.
?>
</div>
</div>
Consider using mysql_fetch_assoc()
instead of mysql_result()
:
$query = "SELECT * FROM releases";
$result = mysql_query($query);
if(!$result) die ("Database access failed: " .mysql_error());
while ($row = mysql_fetch_assoc($result)) {
echo '<img src="' . $row['picture_url'] . '" class="ep" id="' . $rom['release_id'] . '" width= "200" height= "200"/>';
}
mysql_close($db_server);
Since you are beginning with PHP please read: Why shouldn't I use mysql_* functions in PHP?
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.