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 07-15-2008, 09:18 PM   PM User | #1
student101
Regular Coder

 
student101's Avatar
 
Join Date: Nov 2007
Posts: 610
Thanks: 80
Thanked 13 Times in 13 Posts
student101 is on a distinguished road
Question Echo, Print or how to echo to screen?

I found this useful piece of code here;
I was wondering how to print what I need to print on the screen?
PHP Code:
<?php
$sql 
"SELECT * FROM Photos";
$sql1 mysql_query($sql) or die(mysql_error());
if(
mysql_num_rows($sql1) > 0)
{
    
$i 0;
    echo 
'<table border="1">'."\n";
    while(
$result=mysql_fetch_array($sql1))
    {
        if(
$i == 0) echo '<tr>'."\n";
        echo 
'<th scope="col"><img src="photos/'.$result['Filename'].'"></th>'."\n";
        
$i++;
        if(
$i == 0) echo '</tr>'."\n";
    }
    echo 
'</table>';
}
?>
My needs are here:
PHP Code:
<?php
$sql 
$query_rsnav1;
$sql1 mysql_query($sql) or die(mysql_error());
if(
mysql_num_rows($sql1) > 0)
{
    
$i 0;
    echo 
'<table border="0">'."\n";
    while(
$result=mysql_fetch_array($sql1))
    {
    if(
$i == 1) echo '<tr>'."\n";

//start problem area

echo '<th scope="col"><a href="?catid=<?php echo $_GET['catid']; ?>&img=<?php echo $row_rsnav1['image']; ?>&navid=<?php echo $row_rsnav1['intid']; ?>"><img src="uploads/<?php echo $row_rsnav1['thumb']; ?>" alt="" width="100" border="0"/></a></th>'."\n";

//end problem area

    
$i++;
    if(
$i == 1) echo '</tr>'."\n";
    }
    echo 
'</table>';
}
?>
__________________
Thanks for your support!
Update MySQL with checkboxes | Tell A Friend | Delete MySQL with checkboxes

Give thanks & resolve when done :thumbsup:
student101 is offline   Reply With Quote
Old 07-15-2008, 09:29 PM   PM User | #2
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,653
Thanks: 4
Thanked 2,451 Times in 2,420 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
I don't understand you're problem, you'll need to clarify. I'm guessing you just need to change this line:
PHP Code:
//start problem area

echo '<th scope="col"><a href="?catid=' $_GET['catid'] . '&img=' $row_rsnav1['image'] . '&navid=' $row_rsnav1['intid'] . '"><img src="uploads/' $row_rsnav1['thumb'] . '" alt="" width="100" border="0"/></a></th>'."\n"
<?php echo does not belone with a part of a string unless you are filtering it through eval.
__________________
As of PHP 5.5, the MySQL library has been officially deprecated. It is recommended to move to either MySQLi or PDO libraries for your mysql connectivity. See here for help choosing which interface you prefer: http://php.net/manual/en/mysqlinfo.api.choosing.php
Fou-Lu is offline   Reply With Quote
Users who have thanked Fou-Lu for this post:
student101 (07-15-2008)
Old 07-15-2008, 09:34 PM   PM User | #3
student101
Regular Coder

 
student101's Avatar
 
Join Date: Nov 2007
Posts: 610
Thanks: 80
Thanked 13 Times in 13 Posts
student101 is on a distinguished road
That works, as in displaying the images using ?catid=1 but it fills the entire screen with duplicates instead of the one row.

So the same image fills up an entire row, then the next and so on... This is incorrect as there are only 8 images to display, preferably in a horizontal loop. (Tom mucks looper don't work)

What I'm trying to do is use an iframe and drop a horizontal(led) loop of my filtered images using an included iframe in the main page.
__________________
Thanks for your support!
Update MySQL with checkboxes | Tell A Friend | Delete MySQL with checkboxes

Give thanks & resolve when done :thumbsup:

Last edited by student101; 07-15-2008 at 09:42 PM..
student101 is offline   Reply With Quote
Old 07-15-2008, 09:41 PM   PM User | #4
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,653
Thanks: 4
Thanked 2,451 Times in 2,420 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
Oh I see. Its a query issue then:
PHP Code:
<?php
if (!isset($_GET['catid']) || empty($_GET['catid']))
{
    
// I'm just going to default to 1, you can throw an exception or do whatever
    
$catID 1;
}
else
{
    
$catID = (int)$_GET['catID'];
}
$sql "SELECT * FROM Photos WHERE yourcatfield=" $catID;
Might as well change this line too, better to trust you're variables over the get variables:
PHP Code:
//start problem area

echo '<th scope="col"><a href="?catid=' $catID '&img=' $row_rsnav1['image'] . '&navid=' $row_rsnav1['intid'] . '"><img src="uploads/' $row_rsnav1['thumb'] . '" alt="" width="100" border="0"/></a></th>'."\n"
As for duplicates, thats a data integrity thing. You're database might not be normalized allowing duplicate records to exist. You're original query indicates that it always fetches ever record from the Photos regardless of what catid has been chosen.

Is that what you're asking for?
__________________
As of PHP 5.5, the MySQL library has been officially deprecated. It is recommended to move to either MySQLi or PDO libraries for your mysql connectivity. See here for help choosing which interface you prefer: http://php.net/manual/en/mysqlinfo.api.choosing.php
Fou-Lu is offline   Reply With Quote
Old 07-15-2008, 09:54 PM   PM User | #5
student101
Regular Coder

 
student101's Avatar
 
Join Date: Nov 2007
Posts: 610
Thanks: 80
Thanked 13 Times in 13 Posts
student101 is on a distinguished road
No, my code is below the code I found:
PHP Code:
<?php if ($totalRows_rsnav1 0) { // Show if recordset not empty ?>
<?php 
do { ?>
<div class="panel" style="width: 100px">

//////////////////////// Start this part 
<?php 
$sql 
$query_rsnav1;
$sql1 mysql_query($sql) or die(mysql_error());
if(
mysql_num_rows($sql1) > 0)
{
    
$i 0;
    echo 
'<table border="0">'."\n";
    while(
$result=mysql_fetch_array($sql1))
    {
        if(
$i &#37; 1 == 1) echo '<tr>'."\n";
echo '<th scope="col"><a href="?catid=' $_GET['catid'] . '&img=' $row_rsnav1['image'] . '&navid=' $row_rsnav1['intid'] . '"><img src="uploads/' $row_rsnav1['thumb'] . '" alt="" width="100" border="0"/></a></th>'."\n";
        
$i++;
        if(
$i == 1) echo '</tr>'."\n";
    }
    echo 
'</table>';
}
?>
//////////////////////// End this part 

</div>
<?php } while ($row_rsnav1 mysql_fetch_assoc($rsnav1)); ?>
<?php 
// Show if recordset not empty ?>
__________________
Thanks for your support!
Update MySQL with checkboxes | Tell A Friend | Delete MySQL with checkboxes

Give thanks & resolve when done :thumbsup:
student101 is offline   Reply With Quote
Old 07-15-2008, 10:02 PM   PM User | #6
student101
Regular Coder

 
student101's Avatar
 
Join Date: Nov 2007
Posts: 610
Thanks: 80
Thanked 13 Times in 13 Posts
student101 is on a distinguished road
Quote:
Originally Posted by Fou-Lu View Post
Oh I see. Its a query issue then:
As for duplicates, thats a data integrity thing. You're database might not be normalized allowing duplicate records to exist.
This page works on the main page, I wanted to use an iframe and use the navigation on it's own page and include it in the main page. (saves refreshing each time a link is clicked)
I wasn't able to horizontally loop the images - till I found this script that works, except it doesn't.
__________________
Thanks for your support!
Update MySQL with checkboxes | Tell A Friend | Delete MySQL with checkboxes

Give thanks & resolve when done :thumbsup:
student101 is offline   Reply With Quote
Old 07-15-2008, 10:03 PM   PM User | #7
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,653
Thanks: 4
Thanked 2,451 Times in 2,420 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
I'm still confused then, lol.
Can you describe (or show if you have a online page) what it is doing, and indicate what it is that you want it to be doing? Does it require pagination and how many rows/columns do you require this to be displayed in, etc.
__________________
As of PHP 5.5, the MySQL library has been officially deprecated. It is recommended to move to either MySQLi or PDO libraries for your mysql connectivity. See here for help choosing which interface you prefer: http://php.net/manual/en/mysqlinfo.api.choosing.php
Fou-Lu is offline   Reply With Quote
Old 07-15-2008, 10:28 PM   PM User | #8
student101
Regular Coder

 
student101's Avatar
 
Join Date: Nov 2007
Posts: 610
Thanks: 80
Thanked 13 Times in 13 Posts
student101 is on a distinguished road
Quote:
Originally Posted by Fou-Lu View Post
I'm still confused then, lol.
Can you describe (or show if you have a online page) what it is doing, and indicate what it is that you want it to be doing? Does it require pagination and how many rows/columns do you require this to be displayed in, etc.
FIXED!!
I kept calling the wrong recordset value, it should have been $result
PHP Code:
echo '<th scope="col"><a href="?catid=' $_GET['catid'] . '&img=' $result['image'] . '&navid=' $result['intid'] . '"><img src="uploads/' $result['thumb'] . '" alt="" width="100" border="0"/></a></th>'."\n"
Thank you!
__________________
Thanks for your support!
Update MySQL with checkboxes | Tell A Friend | Delete MySQL with checkboxes

Give thanks & resolve when done :thumbsup:
student101 is offline   Reply With Quote
Old 07-15-2008, 10:31 PM   PM User | #9
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,653
Thanks: 4
Thanked 2,451 Times in 2,420 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
If you want to use an iframe (which I do not condone but to each their own), you need to separate you're handling from the rest of it, since an iframe requires a page of its own including all the proper headers. If the correct images are not showing up (ie, you are getting all images), it is likely the query is not handling the category selection correctly. After this, you need all other links to target the iframe, otherwise they will default to themselves, which will reload you're page and give you the original iframe that was selected. You can include an iframe in a table, but you must make sure that proper column and row spanning is performed - iframe tables do not effect the page tables.

Think smaller, if you are for sure using an iframe create a page that accepts the querystring for its lookups and make sure you have everything looking the way you want it to. After that, implement that page into you're primary page by using the iframe. Sticking two working pages together is far easier than trying to break one up into chunks to figure out the problems.

Edit:
Glad you got it fixed!
Sorry, I should have paid more attention when I was rewriting that line to the fact you used $rows_nav1 instead of $result.
__________________
As of PHP 5.5, the MySQL library has been officially deprecated. It is recommended to move to either MySQLi or PDO libraries for your mysql connectivity. See here for help choosing which interface you prefer: http://php.net/manual/en/mysqlinfo.api.choosing.php
Fou-Lu is offline   Reply With Quote
Old 07-15-2008, 10:34 PM   PM User | #10
student101
Regular Coder

 
student101's Avatar
 
Join Date: Nov 2007
Posts: 610
Thanks: 80
Thanked 13 Times in 13 Posts
student101 is on a distinguished road
I only just built the idea today.
It works fine as one full page(with page refreshes) - I didn't want the navigation to loose it's place, due to page refreshes.

I have to spend more time - like you say build it up, not break it down.
Will start again tomorrow.

No probs, thank you!
__________________
Thanks for your support!
Update MySQL with checkboxes | Tell A Friend | Delete MySQL with checkboxes

Give thanks & resolve when done :thumbsup:

Last edited by student101; 07-15-2008 at 10:45 PM..
student101 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 03:26 AM.


Advertisement
Log in to turn off these ads.