Jump to content


Photo

Displaying results over columns


  • Please log in to reply
15 replies to this topic

#1 benji87

benji87
  • Members
  • PipPipPip
  • Advanced Member
  • 136 posts
  • LocationPortsmouth, UK

Posted 20 September 2006 - 02:15 PM

Hi all.

Im looking for a bit of script that will display some sql results over three columns instead of down rows. For image thumbnails.

I know someone has already put up a topic about this i tried to use the script but it was all too much for what im wanting i just want a bare bones script.

Any help would be great!

#2 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,017 posts

Posted 20 September 2006 - 02:41 PM

Have you looked in the forum FAQ

http://www.phpfreaks...ic,95426.0.html
If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#3 benji87

benji87
  • Members
  • PipPipPip
  • Advanced Member
  • 136 posts
  • LocationPortsmouth, UK

Posted 20 September 2006 - 03:06 PM

Thanks for the link that was really useful but its telling the that the msql_fetch_array() is an undefined function??

#4 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 20 September 2006 - 03:10 PM

This is easy connect database make a while loop get the information then format html properly and echo results.

good luck.
Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#5 benji87

benji87
  • Members
  • PipPipPip
  • Advanced Member
  • 136 posts
  • LocationPortsmouth, UK

Posted 20 September 2006 - 03:12 PM

Easy for who? Its only easy if you already know it. Why bother posting if your not willing to help.

Dont reply as i dont want to flame

#6 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 20 September 2006 - 03:14 PM

post what you got then then i do it usally users post code
Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#7 benji87

benji87
  • Members
  • PipPipPip
  • Advanced Member
  • 136 posts
  • LocationPortsmouth, UK

Posted 20 September 2006 - 03:20 PM

Thanks for the help. I did not post code coz its basicly what barand sent me the link to:

<table cellspacing="3" cellpadding="3">
<?php
include ("db.php");
$query = "SELECT img_thumb FROM deck_imgs ORDER BY img_name";
$result = mysql_query($query) or die("There was a problem with the SQL query: " . mysql_error()); 
if($result && mysql_num_rows($result) > 0)
{
    $i = 0;
    $max_columns = 3;
    while($row = mssql_fetch_array($result))        
   {
       // make the variables easy to deal with
       extract($row);

       // open row if counter is zero
       if($i == 0)
          echo "<tr>";

       // make sure we have a valid product
       if($img_thumb != "" && $img_thumb != null)
          echo "<td>$img_name</td>";
    
       // increment counter - if counter = max columns, reset counter and close row
       if(++$i == $max_columns) 
       {
           echo "</tr>";
           $i=0;
       }  // end if 
   } // end while
} // end if results

// clean up table - makes your code valid!
if($i < $max_columns)
{
    for($j=$i; $j<$max_columns;$j++)
        echo "<td>&nbsp;</td>";
}
 ?>
</tr>
</table>


#8 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 20 September 2006 - 03:25 PM

while($row = mssql_fetch_array($result))

to

while($row = mssql_fetch_assoc($result))

Might work
Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#9 benji87

benji87
  • Members
  • PipPipPip
  • Advanced Member
  • 136 posts
  • LocationPortsmouth, UK

Posted 20 September 2006 - 03:29 PM

Nope still the same error :(

#10 HuggieBear

HuggieBear
  • Members
  • PipPipPip
  • Advanced Member
  • 1,899 posts
  • LocationEngland, UK

Posted 20 September 2006 - 03:39 PM

There's a typo that hasn't been noticed.

You're using mysql at the top and then mssql at the bottom... Notice the difference.  You need mysql_fetch_array

Change this:
while($row = mssql_fetch_array($result))

to
while($row = mysql_fetch_array($result))


Regards
Huggie
Advice to MySQL users: Get phpMyAdmin and test your queries work there first, take half the hassle out of diagnosis, also check the reserved words list.

Links: PHP Docs :: RegEx's :: MySQL :: DevGuru :: w3schools

#11 benji87

benji87
  • Members
  • PipPipPip
  • Advanced Member
  • 136 posts
  • LocationPortsmouth, UK

Posted 20 September 2006 - 03:59 PM

Thanks! Its always the obvious things! It worked fine trouble is now it wont display any data!  >:(

#12 HuggieBear

HuggieBear
  • Members
  • PipPipPip
  • Advanced Member
  • 1,899 posts
  • LocationEngland, UK

Posted 20 September 2006 - 04:04 PM

ok,

Try changing this:
while($row = mysql_fetch_array($result))

to:
while($row = mysql_fetch_array($result, MYSQL_ASSOC))


This way, extract($row) will import a variable of $img_name into the namespace, I think by default mysql_fetch_array() gets both names and numbers as an index, but by specifying MYSQL_ASSOC it gets only names, probably less overhead.

Regards
Huggie
Advice to MySQL users: Get phpMyAdmin and test your queries work there first, take half the hassle out of diagnosis, also check the reserved words list.

Links: PHP Docs :: RegEx's :: MySQL :: DevGuru :: w3schools

#13 jerastraub

jerastraub
  • Members
  • PipPipPip
  • Advanced Member
  • 77 posts

Posted 27 September 2006 - 09:44 PM

Hello,

I am kinda new to php. I read the above posts about how to display results over columns:

Here is my code:

<table cellspacing="3" cellpadding="3">
<?php
include ("config.php");
?>
<?php
$query = "SELECT Link,Image, Alt from pluswomens_frontimage_rotator ORDER by rand()";
$result = mysql_query($query) or die("There was a problem with the SQL query: " . mysql_error());
if($result && mysql_num_rows($result) > 0)
{
    $i = 0;
    $max_columns = 3;
    while($row = mysql_fetch_array($result))       
  {
      // make the variables easy to deal with
      extract($row);

      // open row if counter is zero
      if($i == 0)
          echo "<tr>";

      // make sure we have a valid product
      if($product != "" && $product != null)
          echo "<td><td><img src=$Image alt=$Alt border=0 align=bottom hspace=5 vspace=5></td></td>";
   
      // increment counter - if counter = max columns, reset counter and close row
      if(++$i == $max_columns)
      {
          echo "</tr>";
          $i=0;
      }  // end if
  } // end while
} // end if results

// clean up table - makes your code valid!
if($i < $max_columns)
{
    for($j=$i; $j<$max_columns;$j++)
        echo "<td>&nbsp;</td>";
}
?>
</tr>
</table>

This is what displays:

<table cellspacing="3" cellpadding="3">
<tr></tr><tr></tr><tr></tr><tr></tr><tr></tr><tr></tr><tr></tr><tr><td>&nbsp;</td><td>&nbsp;</td></tr>
</table>

Can someone tell me what I am doing wrong, and yes there is information in pluswomens_frontimage_rotator to pull.

#14 HuggieBear

HuggieBear
  • Members
  • PipPipPip
  • Advanced Member
  • 1,899 posts
  • LocationEngland, UK

Posted 28 September 2006 - 11:52 AM

This is the code that's causing problems...

// make sure we have a valid product
if($product != "" && $product != null)
   echo "<td><td><img src=$Image alt=$Alt border=0 align=bottom hspace=5 vspace=5></td></td>";

For the time being, remove the condition and see if it works at all... Try this:

// make sure we have a valid product
// if($product != "" && $product != null) // temporary comment out
   echo <<<HTML
   <td><img src="{$Image}" alt="{$Alt}" border="0" align="bottom" hspace="5" vspace=5></td>
HTML;

Regards
Huggie
Advice to MySQL users: Get phpMyAdmin and test your queries work there first, take half the hassle out of diagnosis, also check the reserved words list.

Links: PHP Docs :: RegEx's :: MySQL :: DevGuru :: w3schools

#15 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,017 posts

Posted 28 September 2006 - 11:59 AM

$product is never set to a value. Try $image instead.
If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#16 jerastraub

jerastraub
  • Members
  • PipPipPip
  • Advanced Member
  • 77 posts

Posted 28 September 2006 - 02:48 PM

You guys are awesome, works like a charm. I have been trying to find a way to do this for months, I guess I just had to come to the right place!!!!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users