Click here to Skip to main content
15,346,895 members
Home / Discussions / Linux, Apache, MySQL, PHP
   

Linux, Apache, MySQL, PHP

 
GeneralRe: SQL to multidimenisonal array Pin
Luc Pattyn21-Dec-10 8:02
sitebuilderLuc Pattyn21-Dec-10 8:02 
GeneralRe: SQL to multidimenisonal array Pin
MacRaider421-Dec-10 10:01
MemberMacRaider421-Dec-10 10:01 
GeneralRe: SQL to multidimenisonal array Pin
Luc Pattyn21-Dec-10 10:09
sitebuilderLuc Pattyn21-Dec-10 10:09 
GeneralRe: SQL to multidimenisonal array Pin
MacRaider421-Dec-10 14:12
MemberMacRaider421-Dec-10 14:12 
AnswerRe: SQL to multidimenisonal array Pin
schwarzenneger21-Dec-10 18:48
Memberschwarzenneger21-Dec-10 18:48 
GeneralRe: SQL to multidimenisonal array Pin
MacRaider422-Dec-10 1:40
MemberMacRaider422-Dec-10 1:40 
GeneralRe: SQL to multidimenisonal array Pin
cjoki22-Dec-10 5:24
Membercjoki22-Dec-10 5:24 
AnswerRe: SQL to multidimenisonal array Pin
cjoki22-Dec-10 5:21
Membercjoki22-Dec-10 5:21 
Try this
<?php
	$dbh = mysql_connect("host","user","password") or die("Can not connect to db.");
	mysql_select_db("your_db_name");
	
	$i = 1;
	$sql = "select name, dept_id, pay_grade from employees";
	$rst = mysql_query($sql) or die("PG: ".__FILE__." ON LINE: ".__LINE__." ERROR: ".mysql_error());
	if(mysql_num_rows($rst)>0)
	{
		echo "<table><tr><th>#</th><th>NAME</th><th><DEPT</th><th>GRADE</th></tr>";
		while($row = mysql_fetch_assoc($rst))
		{
			echo "<tr><td>".$i."</td><td>".$row['name']."</td><td>".$row['dept_id']."</td><td>".$row['pay_grade']."</td></tr>";
			$i++;
		}
		echo "</table>";
	}
	else
	{
	echo "No Results.";
	}
?>


to write to an array is simple...
<?php
	$dbh = mysql_connect("host","user","password") or die("Can not connect to db.");
	mysql_select_db("your_db_name");
	
	$results = array();	
	$sql = "select name, dept_id, pay_grade from employee";
	$rst = mysql_query($sql) or die("PG: ".__FILE__." ON LINE: ".__LINE__." ERROR: ".mysql_error());
	if(mysql_num_rows($rst)>0)
	{		
		while($row = mysql_fetch_assoc($rst))
		{
			$results[$row['name']] = array($row['dept_id'],$row['pay_grade']);
		}		
	}
	else
	{
		echo "No Results.";
	}
	
	echo "<pre>";
	print_r($results);
	echo "</pre>";
?>


Replace the db connection, db select and the sql with what is relavent for your table, db and connection.

The first bit of code will generate a table or report an error message and display those results to a web page. The second assigns the values to an array and then displays the results at the end.

Hope that helps.
GeneralRe: SQL to multidimenisonal array Pin
MacRaider422-Dec-10 6:02
MemberMacRaider422-Dec-10 6:02 
GeneralRe: SQL to multidimenisonal array Pin
cjoki22-Dec-10 6:47
Membercjoki22-Dec-10 6:47 
GeneralRe: SQL to multidimenisonal array Pin
MacRaider422-Dec-10 8:06
MemberMacRaider422-Dec-10 8:06 
Questionwireless internet not running on vmware Pin
AmbiguousName20-Dec-10 6:32
MemberAmbiguousName20-Dec-10 6:32 
AnswerRe: wireless internet not running on vmware Pin
LloydA11120-Dec-10 6:44
MemberLloydA11120-Dec-10 6:44 
Questionhow to measure TCP congestion windows using python ?? Pin
peaceziz19-Dec-10 0:02
Memberpeaceziz19-Dec-10 0:02 
Questionpopulate combo box / dropdown list from mysql Pin
komanche18-Dec-10 22:46
Memberkomanche18-Dec-10 22:46 
AnswerRe: populate combo box / dropdown list from mysql Pin
Luc Pattyn19-Dec-10 2:34
sitebuilderLuc Pattyn19-Dec-10 2:34 
AnswerRe: populate combo box / dropdown list from mysql Pin
Lucian.cornea21-Dec-10 14:52
MemberLucian.cornea21-Dec-10 14:52 
Questionphp Pin
bitayeganeh18-Dec-10 1:40
Memberbitayeganeh18-Dec-10 1:40 
AnswerRe: php Pin
Dr.Walt Fair, PE19-Dec-10 6:17
professionalDr.Walt Fair, PE19-Dec-10 6:17 
AnswerRe: php Pin
cjoki20-Dec-10 4:37
Membercjoki20-Dec-10 4:37 
AnswerRe: php Pin
Luc Pattyn20-Dec-10 6:23
sitebuilderLuc Pattyn20-Dec-10 6:23 
AnswerRe: Manually redirect to error.php & send 404 in HTTP header? Pin
Luc Pattyn16-Dec-10 10:55
sitebuilderLuc Pattyn16-Dec-10 10:55 
GeneralRe: Manually redirect to error.php & send 404 in HTTP header? Pin
User 741604616-Dec-10 11:06
MemberUser 741604616-Dec-10 11:06 
AnswerRe: Manually redirect to error.php & send 404 in HTTP header? Pin
Luc Pattyn16-Dec-10 11:11
sitebuilderLuc Pattyn16-Dec-10 11:11 
GeneralRe: Manually redirect to error.php & send 404 in HTTP header? Pin
User 741604616-Dec-10 11:15
MemberUser 741604616-Dec-10 11:15 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.