Jump to content

Problem with format of printed MySQL table to HTML with PHP


stlshawgo

Recommended Posts

I'm not sure if my problem is with the PHP, MySQL, HTML, or all of the above, but I've used a tutorial from ScriptPlayground (http://scriptplayground.com/tutorials/php/Printing-a-MySQL-table-to-a-dynamic-HTML-table-with-PHP/) to print a table to HTML.

 

My problem isn't that I couldn't get it to work, as you can see from my site, http://dollapal.com/offerlist.php

 

I've used the code on my site,  trying to display a list of offers, with links to each, but I actually have two questions:

 

Is there a way to EXCLUDE columns of the table?  I would rather not show the 'id' or 'points' columns, since they don't offer any worth to the user.  I would also need to hopefully add a dollar sign before the 'pay' quantities if possible.

 

I would also like use the 'title' field as a hyperlink to the URL listed in the 'URL' field, instead of simply printing the URL. 

 

Are there any simple ways to do this and not have it look terrible?  I have included a copy of the script that I'm working with so far.

 

Thank you in advance!

 

[attachment deleted by admin]

Link to comment
Share on other sites

Thank you for that.  That did solve one part of my question easy enough.  I have corrected that problem to display the information that I would like.

 

Do you know of any way to use the 'title' field as a hyperlink to the URL listed in the 'URL' field, instead of just displaying the URL?  I also had the small dollar sign issue, but that is pretty insignificant.

 

Thank you for the help so far!

Link to comment
Share on other sites

You'll need to figure out a way to use a conditional to determine which field is being echoed, and if it's the table's id field, format it with the html <a href tags, using the id as a GET var in the URL string so you can them process it with another script. Otherwise if it's the field containing the price, prepend a $ to the number. If you need help with either of those, just say so.

Link to comment
Share on other sites

Well, I'm kind of assuming that the table has an index. If it's the first field retrieved in each record, you'd need to determine that and format the output to echo it as a link, with the value of the index field in the url. If you're script to retrieve the specific information is called get_more.php, the link should end up something like

 

if($column_num == 0 ) {
echo "<a href=\"get_more.php?id=$row[0]\">See details</a>
} else {
    // just echo it as normally done in the function
}

 

Hope that makes sense to you . . .

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.