Jump to content

[SOLVED] mysql_fetch_array and mysql_fetch_assoc errors within my sript HELP!!


George Botley

Recommended Posts

Hello guys,

 

I am trying to create a CMS.. Very succesfull so far. My past versions have worked as designed however this time I am having errors when attempting to create Gallery Administration.

 

Here is the code...

 

<?

/* Include Configuration Files */
include_once "../config/config.php";

$con = mysql_connect("$server","$dbuser","$dbpass");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("$database", $con);

$result = mysql_query("SELECT * FROM ap_gallery_cat");

while($row = mysql_fetch_array($result)) {

$id_cat = $row['id'];
$title_cat = $row['title'];
echo "<h3 style='margin-left: 28px; font-size: 15px; margin-top: 8px; text-decoration: underline;'>$title_cat</h3>";

$results = mysql_query("SELECT * FROM ap_gallery WHERE category LIKE $title_cat");
$rowe = mysql_fetch_assoc($results);
$photourl = $rowe["photourl"];

echo "<div style='margin-top: 15px; background: #FFF; margin-left: 25px; border: 1px solid rgb(0, 0, 0); padding: 5px
; float: left; clear: right;'>
<img width='250' height='200' src='$photourl'/>
<br />";

echo '
<div style="width: 100%; height: 25px;">
<div style="margin: auto; width: 234px;">
<a class="button" style="margin: auto; width: " href="index.php?ToDo=WebsiteContent/Gallery&delete=yes&id=ID" title="Delete Photo"><span>Remove this Photo From 
The Gallery</span></a>
</div>
</div>

</div>';

}

mysql_close($con);

?>

 

The idea is for the gallery administration is for the page to display the category name from one table, and then display the images under that title for all images within that category (a seperate table)

 

You can probably see this from the above code however when I use this bit of code it shows the following error when executing the $rowe fetch accoc array.

 

Somebody please help, It is paramount that this works.

Fantastic,

 

That sorted that problem, and it is displaying data properly.

 

However... I am now only being shown one image from each category for some strange reason.

 

This is my basic database structure:

 

id photoname photourl category

1 a                 hidden Category 1

2 b                 hidden Category 1

3 c                 hidden Category 2

4 d                 hidden Category 2

 

It is only taking value 1 for category 1 and value 3 for category 2 and not showing any other values.

 

Any ideas.

 

Thanks again.

Well.... the query is in the above quote....

 

But here is the whole code again.....

 

<?

/* Include Configuration Files */
include_once "../config/config.php";

$con = mysql_connect("$server","$dbuser","$dbpass");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("$database", $con);

$result = mysql_query("SELECT * FROM ap_gallery_cat");

while($row = mysql_fetch_array($result)) {

$id_cat = $row['id'];
$title_cat = $row['title'];
echo "<h3 style='margin-left: 28px; width: 100%; float: left; font-size: 15px; margin-top: 8px; text-decoration: underline;'>$title_cat</h3>";

$results = mysql_query("SELECT * FROM ap_gallery WHERE category = '$title_cat' ORDER BY id ASC LIMIT 100");
while($rowe = mysql_fetch_array($results)) {
$photourl = $rowe["photourl"];
$id = $rowe["id"];

echo "<div style='margin-top: 15px; background: #FFF; margin-left: 25px; border: 1px solid rgb(0, 0, 0); padding: 5px
; float: left; clear: right;'>
<img width='250' height='200' src='$photourl'/>
<br />";

echo "
<div style='width: 100%; height: 25px;'>
<div style='margin: auto; width: 234px;'>
<a class='button' style='margin: auto;' href='index.php?ToDo=WebsiteContent/Gallery&delete=yes&id=$id' title='Delete Photo'><span>Remove this Photo From 
The Gallery</span></a>
</div>
</div>

</div>";
}

}

mysql_close($con);

?>

 

 

 

And here is query it's self....

 

$results = mysql_query("SELECT * FROM ap_gallery WHERE category = '$title_cat' ORDER BY id ASC LIMIT 100");
while($rowe = mysql_fetch_array($results)) {
$photourl = $rowe["photourl"];
$id = $rowe["id"];

echo "<div style='margin-top: 15px; background: #FFF; margin-left: 25px; border: 1px solid rgb(0, 0, 0); padding: 5px
; float: left; clear: right;'>
<img width='250' height='200' src='$photourl'/>
<br />";

echo "
<div style='width: 100%; height: 25px;'>
<div style='margin: auto; width: 234px;'>
<a class='button' style='margin: auto;' href='index.php?ToDo=WebsiteContent/Gallery&delete=yes&id=$id' title='Delete Photo'><span>Remove this Photo From 
The Gallery</span></a>
</div>
</div>

</div>";
}

 

 

It still only shows one even when I add a limit with large numbers. I don't understand. My queries usually display multiple entries odd how this one doesn't. Could it be anything to do with the 2nd query being within the first?

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.