View Full Version : Split mysql query into columns:do the job with php or better Css?

05-06-2009, 02:08 PM
So all my doubt is in the title

have a child page who display's many details info about a determinated item on mysql db.
On the display of the child page have a table:


so at the request it the column have 4 images they will display in only one colum..is it possible to "limit" that colum for example in only 2 items:
| images | Description | Date |
tried some snippets of code but im not there:confused:
Would a rather use Css for that kind of job, more simple or PHP to "limit" my colums?

$page_title = 'Article Detail';
//include ('includes/header.html');
require_once ('mysqli_connect.php');
if ( (isset($_GET['art_nome'])) ) { $id = $_GET['art_nome'];
} else { // No valid ID, kill the script.
echo '<p class="error">This page has been accessed in error.</p>';
$q="SELECT artigos.art_nome, artigos.art_desc, artigos.art_price, categorias.cat_nome, imagens.* FROM
imagens INNER JOIN artigos ON imagens.art_nome = artigos.art_nome
INNER JOIN categorias ON imagens.cat_nome = categorias.cat_nome WHERE imagens.art_nome = '$id'";
$r = @mysqli_query ($dbc, $q)
or die("Error: ".mysqli_error($dbc));
echo "<table align=\"center\" table border=\"1\" cellspacing=\"0\">
<td>Item Number</td>";
while ($row = mysqli_fetch_array ($r, MYSQLI_ASSOC)) {
echo "<tr><td>$row[imagem_nome]</td><td>$row[imagem_data]</td><td>$row[imagem_id]</td></tr>";

echo "</table>";
echo $num_rows;

appreciate your comments

05-06-2009, 03:36 PM
ok tables in php are not the best answer to positioning queries at display, rather use Css.
Someone have some samples or tutorials PHP css to look up what i'm searching?
thank u

05-06-2009, 07:34 PM
Use CSS for sure, don't use multiple MySQL queries.

If you put each image in a div tag an "left float" each div, they'll stack left to right, top to bottom.

05-07-2009, 01:46 PM
tried this:
how u could put <div> tags among ure php code?
could u feed me a sample?
thank u

05-07-2009, 04:05 PM
I use echo() for that.

echo "<div>";

05-07-2009, 08:35 PM
tried like that

echo "<Div id=\"gallerycontainer\"<href=\"../images/{$row['imagem_nome']}'
<img src='../images/{$row['imagem_nome']}' border='0'
width='100' height='80'></a>";

05-07-2009, 09:17 PM
It has to be valid HTML though.. your code is going to produce

<Div id="gallerycontainer"<href="../images/filename.jpg' border='0'>
<img src='../images/filename.jpg' border='0' width='100' height='80'></a>

That's not valid.

05-09-2009, 06:26 PM
restarted from zero to make some another tries

require_once ('mysqli_connect.php');
$q="SELECT * FROM imagens";
$result = @mysqli_query ($dbc, $q)
or die("Error: ".mysqli_error($dbc));
while ($rows = mysqli_fetch_array($result))
extract ($rows);
$image_nome = $rows['imagem_nome'];
$image_data = $rows['imagem_data'];
$image_id = $rows['imagem_id'];
<link rel="stylesheet" href="includes/css1.css" type="text/css" media="screen" />
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<div id="container">
<img src="<?php echo "../images/$rows['imagem_nome']" border='0'>

but i get a "parse error, expecting `T_STRING' or `T_VARIABLE' or `T_NUM_STRING" at line 22. :p

05-09-2009, 08:27 PM
Ok, I think we're getting a little beyond the original issue and crossing over into PHP 101 (http://www.php.net/tut) here.

05-09-2009, 09:13 PM
gotta take a look onto ure link. thanks
tried that

<img src="<?php echo "../images/$rows['imagem_nome']" ?>" border='0'>

nope not better always the same error.

05-10-2009, 11:00 PM
<img src="<?php echo "../images/$rows[imagem_nome]" ?>" border='0'>

Voila, it works
ive replaced the code between the DIV tag for

<img src="<?php echo "a href='../images/{$rows['imagem_nome']}'
<img src='../images/{$rows['imagem_nome']}' border='0'
width='100' height='80'></a>" ?>

works, no error on executing the script but doesn't display correctly the image (only u know a little graphic....) and the request has a while loop who normally displays all the images on the db.....
What must i change on my code?
thank u

05-20-2009, 11:23 AM
find some code on CodingForums it works:thumbsup:

$connection = mysql_connect("localhost" , "user" , "pass") or die ("Can't connect to MySQL");
$db = mysql_select_db("com" , $connection) or die ("Can't select database.");

$cols = 2;
$size = (80/$cols) - 5;
$result = mysql_query("SELECT * FROM imagens order by imagem_id desc") or die (mysql_error());
if (mysql_num_rows($result) > 0){
echo <<<CSS
html, body, div{padding:0px; margin:0px;}
.img {padding:10px; hover img: border: 5px solid blue; margin: 0 5px 5px 0;hover:background-color: transparent;}
.cell {width: {$size}%; float:left;}
margin: 100px;
position: absolute;
width: 30%;
<div class="thumbnail">
while ($t = mysql_fetch_object($result)) {
echo <<<HTML
<div class="cell">
<a href=../images/{$t->imagem_nome} border='0'>
<img src='../images/{$t->imagem_nome}' width='100' height='80' border='0'></a>
echo "</div><!--close results div--!>";
} else {
echo "no results";


now how can i reuse the query $connection to display some other information from the table imagens?
must i make another connectioms to the table or can i reuse the query?

05-20-2009, 03:17 PM
$connection isn't a query, it's a connection. The query is $result. And yes you can use $result just like any other array.

05-20-2009, 11:35 PM
u're right $result , may i have a little sample from ure's? or a tutorial?
in any cases outside the loop correct?

05-24-2009, 12:01 AM
tried this

$row2= mysql_fetch_array($query);
$article_name= $row2['art_nome'];
echo $article_name;
while($row = mysql_fetch_array($query))
$image_name = $row['imagem_nome'];
echo $image_name;
$row1= mysql_fetch_array($query);
$image_date = $row1['imagem_data'];
echo $movie_date;

without the css for the moment :mad:
that will be another nightmare :)
so the result: have the field $article_name, the while() loop $image_name is also ok, it works but the field $image_name doesn't appear:rolleyes:why?
any ideas or advices?
i know my code a bit poor maybe i must to know more about classes or some another code upgrade?
thank u

05-25-2009, 09:42 AM
anyone as an idea? tahnkx:thumbsup: