Welcome to WebmasterWorld Guest from 54.226.133.245

Forum Moderators: open

Message Too Old, No Replies

Newbie SQL Question

Newbie SQL Question

     
11:06 am on Jun 18, 2010 (gmt 0)

New User

5+ Year Member

joined:Sept 25, 2008
posts: 23
votes: 0


Using something like the following echo statement how do I ensure three paired datasets are returned?

echo("

" . $row["CD"]. "
" . $row["CD"]. "
" . $row["CD"]. "
<br>
" . $row["title"]. "
" . $row["title"]. "
" . $row["title"]. "

");
}
4:07 pm on June 18, 2010 (gmt 0)

Senior Member

WebmasterWorld Senior Member rocknbil is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Nov 28, 2004
posts:7999
votes: 0


A little more info is required: 1) SQL, mySQL, or some other flavor? 2) What is your select statement?
8:26 am on July 9, 2010 (gmt 0)

New User

5+ Year Member

joined:Sept 25, 2008
posts: 23
votes: 0


I was using MySql.

Just to update on the problem the problem I was having was returning sets of three records at a time which couldnt be done.

This was so I could integrate it into the HTML easily Using Separate Background Color <div> elements to auto set line height. (http://buildinternet.com/2009/07/four-methods-to-create-equal-height-columns/)

I used a single cell HTML calling the record and some PHP to wrap the row tags after every three records were called.

Any other solutions I overlooked please add them on.
5:22 pm on July 9, 2010 (gmt 0)

New User

5+ Year Member

joined:July 9, 2010
posts: 4
votes: 0


If you're trying to get three values from the "cd" column then three values from the "title column", that match each other, you can do that using this:

$cd1 = $row["cd"];
$title1 = $row["title"];
$cd2 = $row["cd"];
$title2 = $row["title"];
$cd3 = $row["cd"];
$title3 = $row["title"];

echo("

" . $cd1. "
" . $cd2. "
" . $cd3. "
<br>
" . $title1. "
" . $title2. "
" . $title3. "

");


Does that answer your question?
5:53 pm on July 9, 2010 (gmt 0)

Senior Member

WebmasterWorld Senior Member rocknbil is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Nov 28, 2004
posts:7999
votes: 0


Just to update on the problem the problem I was having was returning sets of three records at a time which couldnt be done.


How so? Show us your select statement. :-)

$table_rows = null; // to squelch concatenation warnings

$query = "select * from table";

$result = mysql_query($query);
while ($row=mysql_fetch_array($result)) {
$table_rows .= '<li>' . $row['CD'] . ' ' . $row['title'] . '</li>';
}

echo "<ul>$table_rows</ul>";