Main Logo
News and Articles
  • Latest DVD News
  • Latest Blu-Ray News
  • Latest Columns
DVD Reviews
  • Latest DVD Reviews
  • Latest Blu-ray Reviews
  • Search for
Discussion Forums
  • All Forums
  • General
  • Television
  • DVDs & Films
  • Hardware
  • PCs & Mobiles
  • Photography
  • Music
  • Gaming and Consoles
  • MAD
  • Sports
  • Trading
  • Retailer Reviews
  • Bargain Buckets
  • Region Hacks
Your Account
  • Login
  • Create an Account
  • Lost Password
Region Hacks
  • Multi-Region Hacks
  • Hack Help Forum
Support This Site
  • Support This Site
  • About This Site
  • Contact Us
  • Advertise With Us
  • Advertising Policy
  • Privacy Policy

PCs & Mobiles Forum - Any PHP experts here? - Page 1

Google Plus One
Submit to Digg
Submit to Slashdot
Submit to StumbleUpon
Submit to Reddit
Tweet this Page
Share on Facebook

IMPORTANT - Click here to read the Forum Rules before you post!

Create New Thread
Any PHP experts here?
posted by sashenden on Saturday, 14th May 2011, 10:07

Elite

I have inherited a system at work that is used to display names from a MySQL database on a plasma screen. Depending on a condition in the database some names are marked in red to highlight them.

Currently the names are arranged in rows of 10 across the screen, which works fine, but recently when we added extra names we discovered the PHP code has been written in such a way that each row of 10 names is a table. Each table then select a range of names from the database and posts them to the screen like thisQuote:
 "SELECT * FROM 'post' ORDER BY name ASC LIMIT 10,10";
To add more names I have had to create a new table for each row of names, then increment the ASC LIMIT values 11,10  21,10, 31,10  etc.

Is there a quick way to do this that will automatically increase the range when more names are added over time? The code looks really messy and I am sure that there is a better way of doing it but my PHP skills are pretty much non existant.

RE: Any PHP experts here?
posted by JohnnyTV on Saturday, 14th May 2011, 10:33

Elite

It's a little difficult to see exactly what's going on without seeing the database, but if you just change the query to "SELECT * FROM 'post' ORDER BY name ASC" there won't be a limit on the results so it will be dynamic.

RE: Any PHP experts here?
posted by Miles on Saturday, 14th May 2011, 10:58

Elite Donator

The SQL that Johnny's posted will give you all the rows, sorted by name.

Can you grab a screenshot of how you want the resulting table to look? (assuming you want a table that is).

If it was me doing it and you wanted a table, the PHP would look something like this:

Assumption is that you have already established the link to the database and are using the standard MySQL calls (rather than an ODBC link for example).

$sql =  "SELECT * FROM 'post' ORDER BY name ASC"
$result = mysql_query($sql);
if (!$result) {
    die('Could not query:' . mysql_error());
}
echo "";
while ($row = mysql_fetch_assoc($result)) {
echo "<tr>";
for ($i=0; $i < mysql_num_fields($result); $i++) {
echo "";
echo $row[$i];
echo "";
}
echo "</tr>";
}
mysql_free_result($result);
echo "";

This item was edited on Saturday, 14th May 2011, 11:02

RE: Any PHP experts here?
posted by Miles on Saturday, 14th May 2011, 11:00

Elite Donator

The formatting didn't come out too well there...and without my Apache & MySQL server to play on (above done from memory) I may have got the syntax slightly wrong.

The bit I don't like with any SQL is selecting "*" from a database. It's ambiguous.
If someone happens to adjust the schema (i.e. adds / removes fields) then all related code is possibly wrong.

It's better to define the fields explicitly in my opinion, then output them explicitly in the PHP so you know exactly what you're getting.

RE: Any PHP experts here?
posted by Rob Shepherd on Saturday, 14th May 2011, 11:05

Super Admin

Heh, any PHP experts and you ask a SQL question. Winking

By not specifying a LIMIT it would return all possible results for a query, which as Miles shows above can be iterated to give you as many tables as required to show all the results. It's also a much more efficient way of doing it than executing separate queries for each table generated.


Editor
DVD REVIEWER
MYREVIEWER.COM

My Flickr Photostream

RE: Any PHP experts here?
posted by admars on Saturday, 14th May 2011, 11:05

Elite

I don't know php but

http://www.w3schools.com/

has good tutorials and examples I've used for html, .asp, javascript, jscript and sql.

they have a php section

http://www.w3schools.com/php/default.asp

This item was edited on Saturday, 14th May 2011, 11:06

RE: Any PHP experts here?
posted by Miles on Saturday, 14th May 2011, 11:07

Elite Donator

Well, technically it is a PHP question Rob (just that the source of the rows he wants in the table(s)) is derived from an SQL statement Winking

RE: Any PHP experts here?
posted by Rob Shepherd on Saturday, 14th May 2011, 11:10

Super Admin

Technically it was a SQL one! Happy Anyway, I'm moving on now before I declare that PHP is the spawn of satan and the worst language every to grace the universe since VisualBasic...

Editor
DVD REVIEWER
MYREVIEWER.COM

My Flickr Photostream

RE: Any PHP experts here?
posted by Miles on Saturday, 14th May 2011, 11:31

Elite Donator

Quote:
Robert John Shepherd says...
Technically it was a SQL one!

Yeah yeah, I guess so.

Quote:
Robert John Shepherd says...
I'm moving on now before I declare that PHP is the spawn of satan and the worst language every to grace the universe since VisualBasic...
 Awww, don't say that. I love PHP.
I've been using it for years, it's so easy to pick up, and I love the fact you can run it so easily using a LAMP installation for example (unlike IIS which is just a pain in the arse).

I have been doing quite a lot of object oriented PHP recently and have gone back and redesigned a number of my original web applications at work which have had a big performance improvement as a result.

RE: Any PHP experts here?
posted by JohnnyTV on Saturday, 14th May 2011, 11:55

Elite

Mark me as another php fan Happy been using it for years, a million times better than asp (for what I use it for anyway) are you a .net man RJS?

<<< Return to threads
Choose a Page:
1
2

Some images and content © of their respective copyright holders, All Rights Reserved. All images and content © 1999-2012 Reviewer Ltd., All Rights Reserved. DVD Reviewer and its logo is a registered trademark of Reviewer Ltd.