Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

PHP begginer needs help to display MySQL data

Name: Anonymous 2013-05-29 3:04

Hi, /prog/, first time poster here. I'm new to programming, actually I'm just a farmer a bit interested in IT. So I want to make this website where you could compare different kinds of combine harvesters.
I already created a MySQL database which has 63 columns and about a 1000 rows.
I tried basic things and it works, but when I want to do intermadiate things I get stuck.

So I want to make something like this:
http://www.dpreview.com/products/compare/side-by-side?products=nikon_d90&products=nikon_d3&products=nikon_d4&sortDir=ascending

Firstly, what is a best way to get multiple $_GETs with the same name (in this case "products")?

Secondly, what is a best way to dislay results like in DPreview link?

This kind of code is short and does it's job pretty well:

>while($row = mysqli_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['Make'] . "</td>";
echo "<td>" . $row['Model'] . "</td>";
echo "<td>" . $row['FuelTank'] . "</td>";
echo "</tr>";
}

But when I add aditional product to compare I want a new column, and not a new row.

Hope you guys are helpful.

Name: Anonymous 2013-05-29 3:28

I'm not a PHP guy, but for adding multiple rows, you could do a few things: The way to stick with a raw table structure would be to build a 2D array row by row (I think mysqli_result::fetch_array might do this), but then create your table column-of-the-2d-array by column-of-the-2d-array, so that your data gets rotated 90 degrees.  Then sleeker way to do it, I think, would be to use CSS so that you can define an arbitrary number of <div> elements that stack left-to-right, and then within those you can put more absolutely <div> elements to make a top-down table-ish structure (make sure to deal with the CSS alignment, otherwise long entries in one result could throw off the table-like structure).  Then you can just loop through each of your products and fetch the row as you're doing now.

For getting multiple values, it looks like you want explode('&', $_SERVER['QUERY_STRING']), but then you have to loop through the resulting array and do key-value matching yourself by explodeing on '='.  It might be worth it to just set a maximum number of products to compare and pass them all as product1=, product2=, product3=, etc.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List