hosted by liquidweb


Go Back   Web Hosting Talk : Web Hosting Main Forums : Programming Discussion : Programming Tutorials : PHP: Array How to Retrieve & Display from DB
Reply

Programming Tutorials How-Tos related to programming, databases, and the like.
Forum Jump

PHP: Array How to Retrieve & Display from DB

Reply Post New Thread In Programming Tutorials Subscription
 
Send news tip View All Posts Thread Tools Search this Thread Display Modes
  #1  
Old 04-30-2006, 03:52 PM
mr_ash mr_ash is offline
New Member
 
Join Date: Apr 2006
Posts: 0
Exclamation

PHP: Array How to Retrieve & Display from DB


Hi,

I am in need of some serious help here. I am having problems in creating some funtions that will gather categories from my DB:

The function that I have done to do this is:

function get_categories()
{

$conn = mysql_connect('', '', '');
mysql_select_db('', $conn);

$query = "select product_category from PRODUCT_CATEGORY";

$result = @$conn->query($query);
if (!$result)
return false;
$num_cats = @$result->num_rows;
if ($num_cats ==0)
return false;
$result = db_result_to_array($result);
return $result;
}

The problem also lies where I cant get PHP to convert these into an array can anyone help me to construct a function that will put my results into an array and then display them as a link.

Reply With Quote


Sponsored Links
  #2  
Old 05-03-2006, 08:09 AM
adaml adaml is offline
Web Hosting Guru
 
Join Date: Oct 2002
Location: York, United Kingdom
Posts: 260
Welcome to the WebHostingTalk! This should be in the programming discussion forum, its not a tutorial! Anyway, here goes:

PHP Code:
function get_categories() {
   
$conn mysql_connect('''''');
   
$selectDB mysql_select_db(''$conn);


   
$result = @mysql_query($query);
   if (!
$result) {
     return 
false;
   }

   if (@
mysql_num_rows == 0) {
     return 
false;
   }
   while (
$rows mysql_fetch_array($result)) {
      
$categories[] = $rows;
   }

   return 
$categories;

It would be a good idea to set a global connection to the database rather than setting up a new connection in each function that requires a connection. Also you shouldnt use OOP style coding when your doing everything else procedural its bad practise. And try sticking your code in PHP tags when your writing a message!

Try searching on the google for some tutorials and resources and check out www.phpfreaks.com and www.php.net!


Hope this helps!

Reply With Quote
Reply

Related posts from TheWhir.com
Title Type Date Posted
Amazon Web Services Launches Glacier Archive Cloud Storage Web Hosting News 2012-08-21 13:05:10
The Archive Team Saves User Data from Failed Web Hosts Blog 2012-04-13 16:41:54
Web Host webHOSTING.net Improves Data Backup Using Nimble Storage Array Web Hosting News 2012-03-28 13:14:22
Web Host SoftLayer Releases OpenStack-Based Cloud Storage Service Web Hosting News 2012-02-14 13:11:18
Carpathia and Electronic Frontier Foundation Aim to Help Megaupload Users Retrieve Legal Data Web Hosting News 2012-01-31 11:27:26


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes
Postbit Selector

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump
Login:
Log in with your username and password
Username:
Password:



Forgot Password?
Advertisement:
Web Hosting News:



 

X

Welcome to WebHostingTalk.com

Create your username to jump into the discussion!

WebHostingTalk.com is the largest, most influentual web hosting community on the Internet. Join us by filling in the form below.


(4 digit year)

Already a member?