PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
I have an upload system and what I want it to do is to upload an image (that works perfectly) and if everything is correct (works) than it would submit the url, name and the comments submitted about the image into the database (doesn't work) and then create an individual page for the image (works perfectly).
I chose an SQL route for this one... here is my PHP...
I fixed the problem of when it was not submitting the information into the database... it now does that... now what I want is to view the results like I posted above... (in the main - individual page) the following is like a preview of it...
That I want to be viewed in 100px width... the image to be scaled down to width="100px" height="100px" and to have a link around it... in the following format...
the image url, description, and name would be taken off of the database... I have no idea on how to do that... can someone giv eme the PHP code to do that? Please... that would be greatly appreciated...
<?php
include_once('config.php');
//MySQL connection
mysql_connect($dbhost, $dbuser, $dbpass) or die(mysql_error());
//Database connection
mysql_select_db($dbtable) or die(mysql_error());
//Varible to store all retrieved information.
$buffer = array();
//Pull all the data out of the database.
$query = "mysql_query(SELECT url,Name,Description FROM images ORDER BY 'Name') or die(mysql_error()";
$results = 'mysql_query($query) or die(mysql_error()';
$myArray = array();
while($row = mysql_fetch_assoc($query)) {
$myArray[] = $row;
}
foreach($myArray as $rowArray) {
echo '<img src="'. $rowArray['URL'] .'" alt="'. $rowArray['NAME'] .'" /><br />Description:<br /><p>'. $rowArray['DESCRIPTION'] .'</p><br />';
}
?>
I get the following error...
Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in C:\wamp\www\Image distribution\show.php on line 18
<?php
include_once('config.php');
//MySQL connection
mysql_connect($dbhost, $dbuser, $dbpass) or die(mysql_error());
//Database connection
mysql_select_db($dbtable) or die(mysql_error());
//Variable to store all retrieved information.
//Pull all the data out of the database.
$query = "SELECT url, Name, Description FROM images ORDER BY 'Name'";
$results = mysql_query("$query") or die(mysql_error());
$myArray = array();
while($row = mysql_fetch_assoc($query)) {
$myArray[] = $row;
}
echo $rowArray['URL'];
foreach($myArray as $rowArray) {
echo '<img src="'. $rowArray['URL'] .'" alt="'. $rowArray['NAME'] .'" /><br />Description:<br /><p>'. $rowArray['DESCRIPTION'] .'</p>';
}
?>
This is so frustrating... I still get the same error... I can't figure out why
$query = 'sql only';
$results = mysql_query($query) or die(mysql_error());
if ($results)
{
while($row = mysql_fetch_assoc($results))
{
...
}
}
Edit: I see you are doing it that way in your revised post. Check the mysql_num_rows() of your result set before you loop through it. I'm guessing your query isn't pulling any rows.
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.