Page 2 of 3
Posted: Thu Feb 15, 2007 8:32 am
by snappydesigns
Hi shwanky-
I tried your method (even just copying/pasting directly and only using what you have in its own file), but I get this error:
Parse error: syntax error, unexpected '{' in /home/.mavin/mirka/twinpapers.com/browse_donovan_stflats2.php on line 20
which corresponds to the while statement. Any ideas as to why it wouldn't work?
Thanks for your advice in your last post...I'll have to give those a try.
Everah-
Thanks for your praise. I will look into using phpMyAdmin locally. I think that would save me some time (especially when the internet isn't working, like yesterday).
ryuuka-
I'm definitely going to check out the link you sent. I could definitely use all the help and tutorials I can get my hands on.
Posted: Thu Feb 15, 2007 8:41 am
by RobertGonzalez
shwanky wrote:A couple other pointers, you don't need to call mysql_close().
You don't have to, but it is good practise to close your connections, whether it be database connections, file system connection or any other socket type connection.
shwanky wrote:Also, when ever you are submiting information to a mysql database, mysql_real_escape_string($string) and when retrieving it use htmlentities($string, ENT_QUOTES, "UTF-8"); These funcitons will keep you safe from many potentially annoying consequences

.
But as you progress in your development skills, do not rely solely on these. All inputs should be validated and filtered, and if the input fails validation, the script should not process it (don't make the mistake of changing user input, just fail the script on bad inputs).
This code should work, provided all your DB detaila and such arehandled...
Code: Select all
<?php
// Is the table name correct below?
$sql = 'SELECT * FROM `donovandesigs`';
// Remove the mysql_error() call for production
if (!$result = mysql_query($sql))
{
die('Error in the query ' . $sql . ': ' . mysql_error());
}
while ($row = mysql_fetch_array($result)
{
echo '<div class="block">';
// This is where the parse error was
echo '<a href="view_donovanflat.php?pid=' . $row['product_name'] . '"><img src="' . $row['thumb_name'] . '"></a>';
echo '</div>';
}
?>
Posted: Thu Feb 15, 2007 4:36 pm
by snappydesigns
Everah-
Thanks for your code change, but I'm still getting the same parse error

. Due to my lack of knowledge in this area, I really have no idea how to change things or why it's doing it. I did, however, find code on what I need to do on the forum set up by the author of the php/mysql book that I have. I even tested it on my server, and all is good. However, there are a couple of problems. The data is just displayed as text (the thumbnail image's filename and the product name), but I need show the thumbnail image and its product name below the thumbnail image with each linked to the product page.
Here's what I've got so far:
http://twinpapers.com/browse_donovan_flats.php
Here's the code I used:
Code: Select all
<?php
include('header.html');
//connect to the database
include_once('connect_stflats.php');
//get the data
$query = "SELECT thumb_name, product_name FROM donovandesigs";
$result = mysql_query($query);
//set variables and constants.
DEFINE('NUM_COLUMNS', 3);
DEFINE('TABLE_WIDTH', 746);
$record_number = 0;
$column_width = floor(TABLE_WIDTH / NUM_COLUMNS);
echo '<p> </p>';
echo '<table border="0" width="'. TABLE_WIDTH . '" bgcolor=#FFFFFF align="center">';
while($row = mysql_fetch_array($result, MYSQL_NUM))
{
if(fmod($record_number, NUM_COLUMNS) == 0)
echo '<tr>';
//--information for each individual cell in the row
echo '<td width="' . $column_width . '">';
echo '<p>' . $row[0] . ' ' . $row[1] . '</p>';
echo '</td>';
//---
$record_number++;
if(fmod($record_number, NUM_COLUMNS) == 0)
echo '</tr>';
}
echo '</table>';
include('footer.html');
?>
I know that Line 25 is what displays the data:
echo '<p>' . $row[0] . ' ' . $row[1] . '</p>';
So how do I change this so that the thumbnail image is displayed with a link (specifically
view_donovanflat.php?pid={$row['product_name']} ) and that the product name also has the same link? I've tried all kinds of possibilities, but I just keep getting a parse error. Therefore, I'm stuck at this point.
Anyone? Please!! I'm so close here. Thanks a ZILLION in advance

!!
Posted: Thu Feb 15, 2007 5:10 pm
by superdezign
Well I'm just jumping into this huge post, but where are you getting the thumbnail from? I'm sure just using HTML will perform what it is that you need. I.e. don't write "image.jpg," write "<img src='image.jpg' />."
Just put the filename in as you'd usually do it in HTML. If you get a parse error, you're probably not using your concatenation properly.
The link is the same. It'd be
Code: Select all
<a href="view_donovanflat.php?pid=<?=$row['product_name'];?>">
Posted: Thu Feb 15, 2007 9:16 pm
by snappydesigns
Good news...in my madness to figure this out, I got it working:
http://twinpapers.com/browse_donovan_flats2.php
I know there is still work to be done, and my code could be more efficient and streamlined. For now though, I'm just happy that I've got it working. Eventually, I want to paginate the results, but I need to get to work on the product page. With that said, I will probably be back with questions on that.
Thanks everyone for your suggestions, info, and help!
Oh, one more thing, how do I get rid of the blue (purple once clicked) outline around the thumbs? It's not coordinating well with the overall design.
Jen H.

Posted: Thu Feb 15, 2007 9:22 pm
by superdezign
Posted: Thu Feb 15, 2007 10:15 pm
by snappydesigns
superdezign-
worked like a charm...THANKS!
Posted: Thu Feb 15, 2007 11:31 pm
by snappydesigns
Ok, now I'm working on the product page and am already running into problems. Basically, nothing is happening. Here's the code I'm using:
Code: Select all
<?php
include('header.html');
if(isset($_GET['pid'])){
include_once('connect_stflats.php');
$query = mysql_query ("SELECT product_name, product_id, image_name FROM donovandesigs WHERE product_name = $id") or die ("invalid query");
$result = mysql_query ($query);
$row = mysql_fetch_array ($result, MYSQL_ASSOC);
if ($image=@getimagesize ("{$row['image_name']}")){
echo "<div align=\"center\"><img src=\"{$row['image_name']}\" />";
} else {
echo "<div align=\"center\">No Image Available.</div>";
}
}
include('footer.html');
?>
I suppose I just don't know where to begin with this. At this point, I would just be happy if I can get the image to display on the page. I also noticed that on my thumbnails page
http://twinpapers.com/browse_donovan_flats2.php that links have nothing after id= when it should have the product name (the same thing listed underneath the thumbnail).
I've searched through this forum for answers, but I'm coming up with nothing. Any help would be greatly appreciated. Thanks!
Posted: Fri Feb 16, 2007 12:15 am
by RobertGonzalez
You are using $id in your query, but you are never setting it to anything. Try setting $id = $_GET['pid'] before the query. You also have some issues with your query set up. Try this...
Code: Select all
<?php
include('header.html');
if (isset($_GET['pid']))
{
$id = $_GET['pid'];
include_once 'connect_stflats.php';
$query = 'SELECT product_name, product_id, image_name FROM donovandesigs WHERE product_name = ' . $id;
$result = mysql_query ($query) or die('Could not execute the query: ' . mysql_error());
$row = mysql_fetch_array ($result, MYSQL_ASSOC);
if ($image = getimagesize($row['image_name']))
{
echo '<div align="center"><img src="' . $row['image_name'] . '" />';
}
else
{
echo '<div align="center">No Image Available.</div>';
}
}
include('footer.html');
?>
Posted: Fri Feb 16, 2007 9:13 am
by snappydesigns
Still nothing happening. This is frustrating because I don't understand all the syntax.
I mentioned this before, but I'm noticing that on the thumbnails page, the link to the product page is not showing the product name after ...php?id=
The line in the code that specifies the link is:
Code: Select all
echo "<td align=\"center\"><a href=\"view_donovanflat2.php?id={$row['product_name']}\"><img src=\"{$row[0]}\"></a>
<br><a href=\"view_donovanflat2.php?id={$row['product_name']}\">{$row[1]}</a>
</td>";
The fact that I'm specifying that it should use the product name after the id seems to make no difference. What could I be doing wrong?
This seems like it should all be so simple, but I guess it's not

Posted: Fri Feb 16, 2007 10:36 am
by RobertGonzalez
Just before the echo (or before he while loop if you are in a loop) add a var_dump($row). This should output all of the information in the variable $row so you can see what it is in it and how. I would suspect it may have something to do with how you are referencing the array (numeric versus associative).
Posted: Fri Feb 16, 2007 11:05 am
by snappydesigns
Hi Everah-
Thanks for the reply...ok, I did that added it like this:
Code: Select all
var_dump($row);
while($row = mysql_fetch_array($result, MYSQL_NUM))
Now it says NULL above the thumbnails and no change to the links (don't know if it was supposed to do anything since I don't know exactly what var_dump($row) is

).
One thing I did change is added a new column to my table called item_id that is the primary key and is automatically incremented in order to make the links more efficient.
So question:
Should I be doing something beforehand in the code to reference what the id will be? I have it referenced in the view product page but just figured I needed to only link it on this page with no other identifiers.
Posted: Fri Feb 16, 2007 11:08 am
by snappydesigns
Why don't I just post the whole code so you don't just see snippets:
Code: Select all
<?php
include('header.html');
//connect to the database
include_once('connect_stflats.php');
//get the data
$query = "SELECT thumb_name, product_name, item_id FROM donovandesigs";
$result = mysql_query($query);
//set variables and constants.
DEFINE('NUM_COLUMNS', 5);
DEFINE('TABLE_WIDTH', 735);
$record_number = 0;
$column_width = floor(TABLE_WIDTH / NUM_COLUMNS);
echo '<p> </p>';
echo '<table border="0" width="746" bgcolor=#FFFFFF align="center">';
echo '<tr>';
echo '<td><div align="center"><h1>STATIONERY</h1></div></td>';
echo '</tr>';
echo '<tr>';
echo '<td><div align="center"><h3>FLATS</h3></div></td>';
echo '</tr>';
echo '<tr>';
echo '<td><div align="center"><h3>Donovan Designs</h3></div></td>';
echo '</tr>';
echo '<tr>';
echo '<td><table border="0" width="'. TABLE_WIDTH . '" bgcolor=#FFFFFF align="center" cellpadding="10" cellspacing="2">';
var_dump($row);
while($row = mysql_fetch_array($result, MYSQL_NUM))
{
if(fmod($record_number, NUM_COLUMNS) == 0)
echo '<tr>';
echo "<td align=\"center\"><a href=\"view_donovanflat2.php?id={$row['item_id']}\"><img src=\"{$row[0]}\"></a>
<br><a href=\"view_donovanflat2.php?id={$row['item_id']}\">{$row[1]}</a>
</td>";
$record_number++;
if(fmod($record_number, NUM_COLUMNS) == 0)
echo '</tr>';
}
echo '</table>';
echo '</td>';
echo '</tr>';
echo '</table>';
include('footer.html');
?>
SUPER THANKS!
Posted: Fri Feb 16, 2007 11:23 am
by snappydesigns
Hold the phones...I figured it out.
I realized the way the I needed to set it was using {$row[2]} where I used "2" instead of "item_id" because that's the way the other table columns were called up.
Now the links are:
Code: Select all
echo "<td align=\"center\"><a href=\"view_donovanflat2.php?id={$row[2]}\"><img src=\"{$row[0]}\"></a>
<br><a href=\"view_donovanflat2.php?id={$row[2]}\">{$row[1]}</a>
</td>";
So now I'm back to my other problem of not being able to display the image on the product page posted earlier. Any new suggestions? Or what could I be doing wrong?
Posted: Fri Feb 16, 2007 11:32 am
by RobertGonzalez
The reason is that you are telling PHP to fetch the data using numerical indeces using
mysql_fetch_array($result, MYSQL_NUM). Remove the MYSQL_NUM and you will have access to both the numerical and associative array keys.