View Full Version : Styling page doesn't seem to work, plz help
Bar2aYunie
06-17-2010, 07:43 AM
Hello,
I've got a script to create pages from my database, it works great, but I cannot seem to get the styling in order. Can somebody help me out plz?
On the first page, the images and text that is pulled from the database is nicely ordered in a table with a max of 4 columns. Great. However, on the second page (when you click an image of the outputted results), all of the records are listed on one line..... As the page only accepts 5 or 6 of those on one line due to the width of the page, all of the other records aren't seen.
I've tried multiple things, but now I don't see it anymore. Can anybody see what to change to have a four column table again?
Here's my script:
<?php
include("../connection.php");
switch($_GET['step']){
default:
$table = "<table style='width:100%;'>\n";
$result = mysql_query("SELECT DISTINCT thumb_sizecat, sizecat, link_size FROM Folders ORDER BY sizecat") or die (mysql_error());
while($row = mysql_fetch_array($result)){
$row['price1'] = round ((($row['price1']+5) *1.85),0);
$base_m=5;
$row['price11'] = $base_m*(ceil(($row['price1'])/$base_m));
$table.="\t\t<td align='center' style='width:25%;'>"
."<a href='?step=items&size=".urlencode($row['sizecat'])."'><img src='{$row['thumb_sizecat']}' alt='{$row['thumb_sizecat']}' />"
."<br />{$row['sizecat']}</a></td>\n";
$colnum++;if($colnum % 4 == 0) $table.="\t</tr>\n\t<tr>\n";
}
$table .= "\t</tr>\n</table>\n";
echo $table;
break;
case "items":
$sizecat=mysql_real_escape_string($_GET['size']);
echo "<table style='width:100%;'>\r\n\t\t<tr>";
$itemsQuery=mysql_query("SELECT * FROM `Folders` WHERE `sizecat`='{$sizecat}';");
while($item=@mysql_fetch_array($itemsQuery)){
$link="?step=color&size=".urlencode($sizecat)."&id=".urlencode($item['id']);
echo "\t\t<td><a href='{$link}'><img src='{$item['thumb_size']}' alt='{$item['thumb_size']}' /><br /><b>Size:</b>{$item['size']}<br /><b>Final size:</b>{$item['finalsize']}<br /></a></td>\r\n";
$colnum++;if($colnum % 4 == 0) $table.="\t</tr>\r\n\t<tr>\n";
}
echo "</tr></table>\r\n";
break;
case "color":
// The rest here has almost the same codings, so I left it out
break;
}
?>
Thx for helping out!!!
djr33
06-17-2010, 08:31 AM
In this sort of situation, I recommend looking at the generated html output (view>source while viewing the page) then working out what you want that source code to look like. Then go back to the PHP and find the places where you need to change it. Then actually fixing it should be easy (or at least easier).
Bar2aYunie
06-17-2010, 09:11 AM
That is a really good idea, though in this case it doesn't really help me....
I see the table settings, then for the columns I see:
<td align='center' style='width:25%;'>content</td>
<td align='center' style='width:25%;'>content</td>
and so on.
So yeah, that is exactly what it is displaying and what I thought it would output. I don't see the <tr> and </tr> anywhere....
Though... I have no idea how to input that....
I've stated the columns this way:
$colnum++;if($colnum % 4 == 0) $table.="\t</tr>\n\t<tr>\n";
And for the first page, that is exactly what it's displaying.... So I don't know what to edit to get that same result for the second (and other) pages.
Do you? Or did I miss something?
djr33
06-17-2010, 09:32 AM
It looks like that should work. Try echoing the value of $colname with each loop so you can watch what it does.
Bar2aYunie
06-17-2010, 10:10 AM
That's what I thought....
You mean '$colnum'? And how do I do that? Just placing an echo in front of that line gives me the numbers 1 - 100 for some reason and nothing else is changed.
djr33
06-17-2010, 10:55 AM
Ah, yes, typo.
Well, just add echo '####'.$colnum.'####'; after the line with it, so you can see the the number is. Track it and see what happens. (Note: I added the extra symbols just to make it easy to read-- they're not 'doing' anything.)
Bar2aYunie
06-17-2010, 11:28 AM
Yeah thought so. lol
Well.... I'm not sure what I should do with that info... It gives me the numbers 1 to 98 vertically with the four # before and after the numbers. What should I learn from this?
Bar2aYunie
06-18-2010, 05:05 PM
Um, what should I do now with those numbers? Or can somebody else help me out here?
Thx in advance!
djr33
06-18-2010, 11:03 PM
Sorry I haven't noticed this until now.
That means you can follow PHP as it generates the <td>s. So look through it and see if you are getting any <tr>s, and if not, see if you can figure out why.
Another thing you can try is this:
$colnum++;
if($colnum % 4 == 0) {
$table.="\t</tr>\n\t<tr>\n";
echo '######TR#####';
}
If you see "######TR#####" somewhere in your output, then that means that the if statement IS working and something is wrong with the $table.= part. I still don't see anything wrong with it.
So all I'm suggesting here is that you take it apart line by line (and echo things) so that you can check what PHP is doing along the way. Eventually you'll be able to find the part that doesn't make sense.
Without testing on your server it's hard to help you-- so just try yourself by checking like this and finding where PHP is doing something unexpected.
Bar2aYunie
06-19-2010, 12:04 AM
No worries, I thought you might missed the post. I'm really glad that you're back though :) I tried hundreds of things, but it either gives a fatal error or the same result is outputted.
Okay, well I just found out that on the first page that is being outputted, there's no starting '<tr>'. That might be the first odd thing. On the second outputted page, there's no <tr> nor </tr> at all. I tried using the echo's to see what it's doing, so now I know about the <tr>'s, but I still don't know what to do now, since I don't see anything in the table part that is off.
Testing... you mean you need the link to see what it's doing?
If this all isn't working... is there another way to output the table settings? If so, do you know how? I already tried using statements to output a table and then use normal html to get the table itself. But that gives me a whole lot of code (like 2 pages for every switch) and still minor errors (displaying double results). So I'm kinda out of idea's, lol.
Thx very much for helping!
djr33
06-19-2010, 01:53 AM
I mean that to test this, you need full access to your server: change the PHP code (such as adding echo statements like I did, and then actually fixing the code) and looking at what happens when you run it. Just looking at the PHP code doesn't help because it looks fine, but clearly something in the actual process of generating html is wrong-- so you need to have access to test it.
I still suggest that you compare your desired output to the real output and take it on step at a time. It's likely that there are a number of problems, but trying to fix them all at once will be confusing. Just do one at a time and figure out specifically what is not happening. PHP doesn't do anything mysterious: it operates line by line. And to debug it, you will need to operate line by line as well-- think like the program and go step by step to find out where it's wrong. Using tricks like "echo" above will help because you can check that at a certain point it's still correct (or incorrect).
Bar2aYunie
06-21-2010, 09:40 AM
Okay great, I am working on it.
I do have another question...
I've got the following line to generate the url:
$link="?step=color&sizecat=".urlencode($sizecat)."&finalsize=".urlencode($item[finalsize]);
In this case, the sizecat is 'Square XL' and the finalsize is '21 x 21 cm'. When I use only the first part of this link (so only the sizecat), the complete url is working. However, I now need to display the items where the sizecat and the finalsize are chosen.
It creates the following url:
/Folders_Formaten2.php?step=color&sizecat=Square+XL&finalsize=21+x+21+cm
The url displays the correct data, but it keeps showing an empty page (though I know there should be results as calling this in the database gives me results).
Do you know what I am doing wrong or how I can fix this?
djr33
06-21-2010, 10:27 AM
That is generating the correct URL, right?
So that means the problem is on the page receiving this information.
One reason may be the spaces that become plus signs-- spaces aren't good for variables like that, so try removing them and see if it helps.
Bar2aYunie
06-21-2010, 10:40 AM
No difference. still an empty page, eventhough I deleted the spaces. I tried another approach for the styling. That does work, but maybe it messes up the next page?
Here's my current code. I also added in the next step, since I cannot seem to get the link to that step correctly....
<?php switch($_GET['step']){
case "items":
$column=2;
$sizecat=mysql_real_escape_string($_GET['size']);
echo "<table style='width:100%;'>\n\t\t<tr>";
$itemsQuery=mysql_query("SELECT DISTINCT thumb_sizecat, sizecat, link_size, size, thumb_size, finalsize FROM `Folders` WHERE `sizecat`='{$sizecat}';");
while($item=mysql_fetch_array($itemsQuery)){
$link="?step=color&sizecat=".urlencode($sizecat)."&finalsize=".urlencode($item['finalsize']);
if ($column==2) {echo "<tr>";}
?>
<td width="25%" align="center"><?php echo "<a href='{$link}'><img src='{$item['thumb_size']}' alt='{$item['thumb_size']}' /><br />{$item['size']}<br />{$item['finalsize']}<br /></a>" ?></td>
<?php
$column++; if ($column==6) { echo "</tr>"; $column=2; }
}
echo "</tr><tr><td align='center' colspan='4'><input type=button value='Back' onClick='history.go(-1)'></td></tr></table>\r\n";
break;
case "color":
$column=2;
$finalsize=mysql_real_escape_string($_GET['finalsize']);
echo "<table style='width:100%;'>\n\t\t<tr>";
$colorQuery=mysql_query("SELECT DISTINCT thumb_sizecat, sizecat, link_size, size, thumb_size, finalsize, color, link_color, thumb_color FROM `Folders` WHERE `finalsize`='{$finalsize}';");
while($item=mysql_fetch_array($colorQuery)){
$link="?step=material&finalsize=".urlencode($finalsize)."&finalsize=".urlencode($item['finalsize']);
if ($column==2) {echo "<tr>";}
?>
<td width="25%" align="center"><?php echo "<a href='{$link}'><img src='{$item['thumb_color']}' alt='{$item['thumb_color']}' /><br />{$item['color']}<br /></a>" ?></td>
<?php
$column++; if ($column==6) { echo "</tr>"; $column=2; }
}
echo "</tr><tr><td align='center' colspan='4'><input type=button value='Back' onClick='history.go(-1)'></td></tr></table>\r\n";
break;
default:
$table = "<table style='width:100%;'><tr>\n";
$result = mysql_query("SELECT DISTINCT thumb_sizecat, sizecat, link_size FROM Folders ORDER BY id") or die (mysql_error());
while($row = mysql_fetch_array($result)){
$row['price1'] = round ((($row['price1']+5) *1.85),0);
$base_m=5;
$row['price11'] = $base_m*(ceil(($row['price1'])/$base_m));
$table.="\t\t<td align='center' style='width:25%;'>"
."<a href='?step=items&size=".urlencode($row['sizecat'])."'><img src='{$row['thumb_sizecat']}' alt='{$row['thumb_sizecat']}' />"
."<br />{$row['sizecat']}</a></td>\n";
$colnum++;if($colnum % 4 == 0) $table.="\t</tr>\n\t<tr>\n";
}
$table .= "\t</tr>\n</table>\n";
echo $table;
break;
}
?>
What do you think?
edit: and yeah, it's for generating the correct url
bluewalrus
06-21-2010, 01:39 PM
Your missing closing semi colons on 2 of your echos..
if ($column==2) {echo "<tr>";}
?>
<td width="25%" align="center"><?php echo
at the end of those
Bar2aYunie
06-21-2010, 09:17 PM
Your missing closing semi colons on 2 of your echos..
if ($column==2) {echo "<tr>";}
?>
<td width="25%" align="center"><?php echo
at the end of those
Sorry, what? I'm confused, what do you mean?
Bar2aYunie
06-21-2010, 10:14 PM
Well, after hours of puzzling, I figured out the problem. I do have something else I wanna ask you.... (which might save me hours of puzzling, haha)
Here's my code:
$sizecat=mysql_real_escape_string($_GET['sizecat']);
$finalsize=$_GET['finalsize'];
$thumb_size=$_GET['thumb_size'];
$color=$_GET['color'];
$material=$_GET['material'];
echo "<table style='width:100%;'>\n\t\t<tr><td align='center' colspan='4'><h1>View Prices</h1></td></tr><tr>";
$finalQuery=mysql_query("SELECT DISTINCT thumb_size, size, totalsize, Info, material, thumb_material, finalsize, color FROM `Folders` WHERE `sizecat`='{$sizecat}' AND `finalsize`='{$finalsize}' AND `color`='{$color}' AND `material`='{$material}' AND `thumb_size`='{$thumb_size}';");
The select query works for the whole line except for the thumb_size... Without that last part, the query returns three rows (and I only need it to return one row). The thumb_size and the totalsize are the only two things in the database that have their own unique data, unique for every entry. So, to be able to get only one row returned from the query, I need one of those at the end of the query (the others wouldn't even be needed actually).
But both of them don't work.... Any idea's??
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.