Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-29-2007, 09:10 PM   PM User | #1
edawg
New to the CF scene

 
Join Date: Jan 2007
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
edawg is an unknown quantity at this point
Cool PHP loops problem.

Hi, I'm trying to update a current pictures site from html into php with a mysql backend, im pretty new to php and mysql and have run into a problem I cant seem to remedy??, any help would be great!.

I have set up the database, and in the database I have 2 tables so far, one is for the pictures categories which has the names of the categories, and the urls, and the other is for the pictures which has the title of the pictures, and filenames and description, so I linked them both with a associated primary/foreign key relationship.

Now my problem is with a section on my site I would like the latest pictures posted to be shown, so I used a href so you can click on anyone and it will take you to that pictures category, the only problem is I get the latest pictures showing up fine, but when I put the mouse on them the url is the same all the way down, rather than change for each individual picture category, it stays the same link?, ive tried as much as I know so far, but still the same problems?, what can I do?.

PHP Code:
mysql_select_db($database, $connDB) OR DIE ('Unable To Select That Database' . mysql_error() );

$query_sPictures = "SELECT site_pictures.sp_filename_TN, site_pictures.sp_ALT FROM site_pictures ORDER BY site_pictures.sp_timestamp ASC";
 
$sPictures = @mysql_query($query_sPictures, $connDB) or die(mysql_error());
$row_sPictures = mysql_fetch_assoc($sPictures);
$totalRows_sPictures = mysql_num_rows($sPictures);  <-- This part works fine
?> 

<?php
$query_sCategories 
"SELECT site_categories.sc_url FROM site_categories, site_pictures WHERE site_pictures.sc_id = site_categories.sc_id";
 
$sCategories = @mysql_query($query_sCategories$connDB) or die(mysql_error());
$row_sCategories mysql_fetch_assoc($sCategories);
$totalRows_sCategories mysql_num_rows($sCategories);
?>

<?php do { ?><a href="<?php echo $row_sCategories['sc_url'];?>"> <-- This is where the problem is??.

<img src="pictures/<?php echo $row_sPictures['sp_filename_TN']; ?>" alt="<?php echo $row_sPictures['sp_ALT'];?>"></img>[/url]

<?php } while ($row_sPictures mysql_fetch_assoc($sPictures));


mysql_close();?>
Any help would be great, im pulling my hair out with this!!!!!!.
Other forums have not been too helpfull!!.
edawg is offline   Reply With Quote
Old 01-29-2007, 09:25 PM   PM User | #2
angst
Senior Coder

 
angst's Avatar
 
Join Date: Apr 2004
Location: Toronto, Ontario
Posts: 2,112
Thanks: 15
Thanked 122 Times in 122 Posts
angst is on a distinguished road
just a note:
if your code was cleaner more people would look at it.

PHP Code:
<%
mysql_select_db($database$connDB) OR DIE ('Unable To Select That Database' mysql_error() ); 

$query_sPictures "SELECT site_pictures.sp_filename_TN, site_pictures.sp_ALT FROM site_pictures ORDER BY site_pictures.sp_timestamp ASC"
$sPictures = @mysql_query($query_sPictures$connDB) or die(mysql_error()); 
$row_sPictures mysql_fetch_assoc($sPictures); 
$totalRows_sPictures mysql_num_rows($sPictures);

$query_sCategories "SELECT site_categories.sc_url FROM site_categories, site_pictures WHERE site_pictures.sc_id = site_categories.sc_id"
$sCategories = @mysql_query($query_sCategories$connDB) or die(mysql_error()); 
$row_sCategories mysql_fetch_assoc($sCategories); 
$totalRows_sCategories mysql_num_rows($sCategories); 

while (
$row_sPictures mysql_fetch_array($sPictures)) {
    echo 
"<a href='" $row_sCategories['sc_url'] . "'><img src='pictures/" $row_sPictures['sp_filename_TN'] . "' alt='" $row_sPictures['sp_ALT'] . "' /></a>";
}

mysql_close();
?> 
try that.
angst is offline   Reply With Quote
Old 01-29-2007, 09:26 PM   PM User | #3
martialtiger
New Coder

 
Join Date: Jul 2006
Posts: 44
Thanks: 0
Thanked 0 Times in 0 Posts
martialtiger is an unknown quantity at this point
Why not do something like this in lieu of the code you provided.

PHP Code:
<?php
$qry 
"SELECT sp.sp_filename_TN, sp.sp_ALT, sc.sc_url FROM site_categories sc, site_pictures sp WHERE sp.sc_id = sc.sc_id ORDER BY sp.sp_timestamp ASC";
$rslt = @mysql_query($qry$connDB) or die(mysql_error());
$total_rows mysql_num_rows($rslt);
while (
$row mysql_fetch_assoc($rslt)){
  echo 
"<a href=\"$row['sc_url']\"><img src=\"pictures/$row['sp_filename_TN']\" alt=\"$row['sp_ALT']\"></a>";
}
mysql_close($connDB);
?>
martialtiger is offline   Reply With Quote
Old 01-29-2007, 09:29 PM   PM User | #4
angst
Senior Coder

 
angst's Avatar
 
Join Date: Apr 2004
Location: Toronto, Ontario
Posts: 2,112
Thanks: 15
Thanked 122 Times in 122 Posts
angst is on a distinguished road
haha, i didn't even wanna think that much about it,
sort of hurts just to look at ;-P

but, practice makes perfect
angst is offline   Reply With Quote
Old 01-29-2007, 09:33 PM   PM User | #5
martialtiger
New Coder

 
Join Date: Jul 2006
Posts: 44
Thanks: 0
Thanked 0 Times in 0 Posts
martialtiger is an unknown quantity at this point
Quote:
Originally Posted by angst View Post
haha, i didn't even wanna think that much about it,
sort of hurts just to look at ;-P

but, practice makes perfect
Couldn't agree with you more, Angst. My intial response was directed to eDawg and didn't mean to seem like I was commenting on your suggestion.

eDawg,
As Angst suggested please try to clean up your code before just copying and pasting. This will help others when then attempt to look through your code to help.

Good luck!
martialtiger is offline   Reply With Quote
Old 01-29-2007, 09:39 PM   PM User | #6
edawg
New to the CF scene

 
Join Date: Jan 2007
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
edawg is an unknown quantity at this point
Smile

Quote:
Originally Posted by martialtiger View Post
Why not do something like this in lieu of the code you provided.

PHP Code:
<?php
$qry 
"SELECT sp.sp_filename_TN, sp.sp_ALT, sc.sc_url FROM site_categories sc, site_pictures sp WHERE sp.sc_id = sc.sc_id ORDER BY sp.sp_timestamp ASC";
$rslt = @mysql_query($qry$connDB) or die(mysql_error());
$total_rows mysql_num_rows($rslt);
while (
$row mysql_fetch_assoc($rslt)){
  echo 
"<a href=\"$row['sc_url']\"><img src=\"pictures/$row['sp_filename_TN']\" alt=\"$row['sp_ALT']\"></a>";
}
mysql_close($connDB);
?>
Hi, and thanks for your help!!!, I will clean up code in the future, because ill probably be in here alot.

I just tried the code you gave me, but get this error,

Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE,
expecting T_STRING or T_VARIABLE or T_NUM_STRING in file/latest_pictures.php on line 6

edawg is offline   Reply With Quote
Old 01-29-2007, 09:46 PM   PM User | #7
martialtiger
New Coder

 
Join Date: Jul 2006
Posts: 44
Thanks: 0
Thanked 0 Times in 0 Posts
martialtiger is an unknown quantity at this point
Try this
PHP Code:
<?php
$qry 
"SELECT sp.sp_filename_TN, sp.sp_ALT, sc.sc_url FROM site_categories sc, site_pictures sp WHERE sp.sc_id = sc.sc_id ORDER BY sp.sp_timestamp ASC";
$rslt = @mysql_query($qry$connDB) or die(mysql_error());
$total_rows mysql_num_rows($rslt);
while (
$row mysql_fetch_assoc($rslt)){
  echo 
"<a href=\"" $row['sc_url'] . "\"><img src=\"pictures/" $row['sp_filename_TN'] . "\" alt=\"" $row['sp_ALT'] . "\"></a>";
}
mysql_close($connDB);
?>
If that doesn't fix it you may need to insert the codes 1-10 of lastest_pictures.php just so we can take a look further into it.
martialtiger is offline   Reply With Quote
Old 01-29-2007, 09:47 PM   PM User | #8
angst
Senior Coder

 
angst's Avatar
 
Join Date: Apr 2004
Location: Toronto, Ontario
Posts: 2,112
Thanks: 15
Thanked 122 Times in 122 Posts
angst is on a distinguished road
make sure to clean up any white spaces ( blank spaces ).
the code looks ok otherwise.
angst is offline   Reply With Quote
Old 01-29-2007, 10:03 PM   PM User | #9
edawg
New to the CF scene

 
Join Date: Jan 2007
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
edawg is an unknown quantity at this point
All I can say is thank for both of your help!!!, I actually modified it some more into this -->

PHP Code:
<?php
$qry 
"SELECT sp.sp_filename_TN, sp.sp_ALT, sc.sc_url FROM site_categories sc, site_pictures sp WHERE sp.sc_id = sc.sc_id ORDER BY sp.sp_timestamp ASC";
$rslt = @mysql_query($qry$connDB) or die(mysql_error());
$row_result mysql_fetch_assoc($rslt);
$total_rows mysql_num_rows($rslt);?>
<?php
do { ?><a href="<?php echo $row_result['sc_url']; ?>"><img src="pictures/<?php echo $row_result['sp_filename_TN'];?>" alt="<?php echo $row_result['sp_ALT']; ?>"></a>
<?php } while ($row_result mysql_fetch_assoc($rslt)) ;

mysql_close($connDB);

?>
And it now works!! , I could not of done it without your help!!, and I learned along the way!!.
edawg is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 08:41 PM.


Advertisement
Log in to turn off these ads.