Author Topic: Multi column/row output from MySQL query....  (Read 903 times)

0 Members and 1 Guest are viewing this topic.

Offline Lost NinjaTopic starter

  • Irregular
  • Posts: 3
    • View Profile
Multi column/row output from MySQL query....
« on: February 05, 2007, 06:18:00 AM »
Had a good look for this both here and through google, not even sure I'm asking the right question.  :-\

I have a two table DB to store photos for myself and my family to view. One table stores the actual images (actually links) and the other stores categories. To view the pages I have a homepage with a drop down that then sorts by the category.: http://www.incessant-logic.net/gallery/index.php that then hops to an index page that lists five images plus a paging sript to move on five images and back etc...: http://www.incessant-logic.net/gallery/list.php?cat=2 .

Now here is where I'm having issues, I really want this page to look like my normal index page: index page but have it assembled from the database rather than being static. I can display horizontally, or vertically but can't work out how to do both for X number of records. :(

I found a tutorial on Codewalkers.com (http://codewalkers.com/tutorials/15/1.html) that should work but doesn't, or I can't make it work. Can anyone recomend a different tutorial or guide that would help me crack this issue?

And I know there are easy to install/use gallery scripts but using one doesn't help me learn how to make my own. :D But if anyone knows of one thats really easy to use that I could look at to how it works in practice that might be handy too.

Offline Lost NinjaTopic starter

  • Irregular
  • Posts: 3
    • View Profile
Re: Multi column/row output from MySQL query....
« Reply #1 on: February 05, 2007, 07:15:32 AM »
After a fair bit more searching I found this: http://www.tom-muck.com/extensions/help/HorizontalLooper/ which supposedly dos what I want... however the code it inserts is a little beyond my level of expertise. And it doesn't work. :-\

Code: [Select]
<?php require_once('Connections/il_db.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function 
GetSQLValueString($theValue$theType$theDefinedValue ""$theNotDefinedValue ""
{
  
$theValue get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;

  
$theValue function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch (
$theType) {
    case 
"text":
      
$theValue = ($theValue != "") ? "'" $theValue "'" "NULL";
      break;    
    case 
"long":
    case 
"int":
      
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case 
"double":
      
$theValue = ($theValue != "") ? "'" doubleval($theValue) . "'" "NULL";
      break;
    case 
"date":
      
$theValue = ($theValue != "") ? "'" $theValue "'" "NULL";
      break;
    case 
"defined":
      
$theValue = ($theValue != "") ? $theDefinedValue $theNotDefinedValue;
      break;
  }
  return 
$theValue;
}
}

$colname_list_imgs "-1";
if (isset(
$_GET['cat'])) {
  
$colname_list_imgs = (get_magic_quotes_gpc()) ? $_GET['cat'] : addslashes($_GET['cat']);
}
mysql_select_db($database_il_db$il_db);
$query_list_imgs sprintf("SELECT * FROM gallery_img, gallery_cat WHERE gallery_img.img_cat = %s AND gallery_img.img_cat = gallery_cat.img_cat_id ORDER BY img_uid ASC"GetSQLValueString($colname_list_imgs"int"));
$list_imgs mysql_query($query_list_imgs$il_db) or die(mysql_error());
$row_list_imgs mysql_fetch_assoc($list_imgs);
$totalRows_list_imgs mysql_num_rows($list_imgs);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Category Display</title>
<link href="styles/main.css" rel="stylesheet" type="text/css" />
</head>

<body>
<table >
<tr>
<?php
$None_endRow 
0;
$None_columns 5// number of columns
$None_hloopRow1 0// first row flag
do {
    if(
$None_endRow == 0  && $None_hloopRow1++ != 0) echo "<tr>";
   
?>

<td><a href="display.php?uid=<?php echo $row_list_imgs['img_uid']; ?>"><img src="sets/<?php echo $row_list_imgs['img_dir']; ?>/thumbs/img_<?php echo $row_list_imgs['img_name']; ?>_thumb.jpg" alt="<?php echo $row_list_imgs['img_title']; ?>" />
<br />
<?php echo $row_list_imgs['img_title']; ?></a></td>
<?php  $None_endRow++;
if(
$None_endRow >= $None_columns) {
  
?>

</tr>
<?php
 $None_endRow 
0;
  }
} while (
$row_None mysql_fetch_assoc($None));
if(
$None_endRow != 0) {
while (
$None_endRow $None_columns) {
    echo(
"<td>&nbsp;</td>");
    
$None_endRow++;
}
echo(
"</tr>");
}
?>

</table>
</body>
</html>
<?php
mysql_free_result
($list_imgs);
?>


That gives an error on line 69:
Code: [Select]
} while ($row_None = mysql_fetch_assoc($None));[/quote]

But i have no idea what is wrong. Any help?

Offline Lost NinjaTopic starter

  • Irregular
  • Posts: 3
    • View Profile
Re: Multi column/row output from MySQL query....
« Reply #2 on: February 05, 2007, 08:30:34 AM »
Sorry can't see how to edit the above.  :-\

I have it working... well sort of the code works but can't seem to break it out of its tables and into lists for ease of use with CSS.

I'll get there. :D

-edit-: hmm can modify this post but not other two... :(