anthonydamasco Posted August 1, 2006 Share Posted August 1, 2006 Alright here is my issue, I'm very new to php, but I've learned alot, I know how to post to mysql database and manage it, but i dont know how to pull information.I need to pull information from 1 row out of a database and put it into a printable table,can someone show me code examples of how this could be done?this is what i have so far[code=php:0]<?php//connect$conn = mysql_connect("localhost","www2","*******") or die ("cannot connect");$db = mysql_select_db("accu") or die( "Unable to select database");if (get_magic_quotes_gpc()){$orderid = mysql_real_escape_string(stripslashes($_REQUEST['id']));} else {$orderid = mysql_real_escape_string($_REQUEST['id']);}?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/16238-php-and-mysql-help/ Share on other sites More sharing options...
king arthur Posted August 1, 2006 Share Posted August 1, 2006 What is the name of your table, what are the column names and which row do you want the data from? Quote Link to comment https://forums.phpfreaks.com/topic/16238-php-and-mysql-help/#findComment-67252 Share on other sites More sharing options...
wildteen88 Posted August 1, 2006 Share Posted August 1, 2006 Here is a quick example:[code=php:0]<?php//connect$conn = mysql_connect("localhost", "www2", "*******") or die ("cannot connect");$db = mysql_select_db("accu") or die( "Unable to select database");if (get_magic_quotes_gpc()){ $orderid = stripslashes($_REQUEST['id']);}$orderid = mysql_real_escape_string($_REQUEST['id']);$sql = "SELECT * FROM tbl_name WHERE id_field='$orderid'";$result = mysql_query($sql, $conn);echo '<table border="0" cellpadding="0" cellspacing="0">';// now we display the results:$row = mysql_fetch_assoc($result){ echo '<tr><td>' . implode('</td><td>', $row) . "</td></tr>\n";}echo '</table>';?>[/code]Make sure you change [b]tbl_name[/b] to the actual table you are going to be querying in the accu database. Also change [b]id_field[/b] field with the name of the field that contains the id.Also you might want to go through the tutorials over at [url=http://www.php-mysql-tutorial.com/]php-mysql-tutorials.com[/url] Quote Link to comment https://forums.phpfreaks.com/topic/16238-php-and-mysql-help/#findComment-67254 Share on other sites More sharing options...
anthonydamasco Posted August 1, 2006 Author Share Posted August 1, 2006 well I'll show you what i got so far[code=php:0]<?php//connect$conn = mysql_connect("localhost","www2","***") or die ("cannot connect");$db = mysql_select_db("accu") or die( "Unable to select database");if (get_magic_quotes_gpc()){$orderid = mysql_real_escape_string(stripslashes($_REQUEST['id']));} else {$orderid = mysql_real_escape_string($_REQUEST['id']);}$query = "SELECT * FROM joborder WHERE id='" . $orderid . "'";//now send the query to the DB$result = mysql_query($query);//now read the results, i'm assuming your only looking for one row, so$my_row = mysql_fetch_array($result, MYSQL_ASSOC) or die ( mysql_error() );print_r($my_row); error_reporting(E_ALL);ini_set('display_errors','on');?>[/code]This is what someone else told me to use, but it doesnt worki get this error, "Unknown column 'id' in 'where clause'" Quote Link to comment https://forums.phpfreaks.com/topic/16238-php-and-mysql-help/#findComment-67256 Share on other sites More sharing options...
king arthur Posted August 1, 2006 Share Posted August 1, 2006 Then tell us what your column names are. Quote Link to comment https://forums.phpfreaks.com/topic/16238-php-and-mysql-help/#findComment-67259 Share on other sites More sharing options...
wildteen88 Posted August 1, 2006 Share Posted August 1, 2006 Okay thats fine. Change:[code]$my_row = mysql_fetch_array($result, MYSQL_ASSOC) or die ( mysql_error() );print_r($my_row);[/code]with:[code]echo '<table border="0" cellpadding="0" cellspacing="0">';// now we display the results:$my_row = mysql_fetch_assoc($result) or die ( mysql_error() );echo "\n<tr><td>" . implode('</td><td>', $my_row) . "</td></tr>\n";echo '</table>';[/code] Quote Link to comment https://forums.phpfreaks.com/topic/16238-php-and-mysql-help/#findComment-67264 Share on other sites More sharing options...
anthonydamasco Posted August 1, 2006 Author Share Posted August 1, 2006 My Colsorderid - keyusedbefore nearestlocationcompanynamefirstnamelastnamedepartmentphonefaxaddressaddresstwocitystatecountryzippositiontypepositionclassificationpositiontitleemployeesneededtimeneededstartdateworkinghoursworkAddressworkaddresstwoworkcityworkstateworkzippositiondescriptionskillsrequirededucationrequiredadditionalrequirements Quote Link to comment https://forums.phpfreaks.com/topic/16238-php-and-mysql-help/#findComment-67266 Share on other sites More sharing options...
wildteen88 Posted August 1, 2006 Share Posted August 1, 2006 Please read my thread above. This is what your code should be:[code=php:0]<?phperror_reporting(E_ALL);ini_set('display_errors','on');//connect$conn = mysql_connect("localhost","www2","***") or die ("cannot connect");$db = mysql_select_db("accu") or die( "Unable to select database");if (get_magic_quotes_gpc()){ $orderid = stripslashes($_REQUEST['id']);}$orderid = mysql_real_escape_string($_REQUEST['id']);$query = "SELECT * FROM joborder WHERE id='" . $orderid . "'";//now send the query to the DB$result = mysql_query($query);echo '<table border="0" cellpadding="0" cellspacing="0">';// now read the results, i'm assuming your only looking for one row, so$my_row = mysql_fetch_assoc($result) or die ( mysql_error() );echo "\n<tr><td>" . implode('</td><td>', $my_row) . "</td></tr>\n";echo '</table>';?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/16238-php-and-mysql-help/#findComment-67269 Share on other sites More sharing options...
anthonydamasco Posted August 1, 2006 Author Share Posted August 1, 2006 ok it works now how to i get http://www2.accustaffing.com/rrform.php?id=1into a table?let me rephrase that, I need to be able to show this content in differant cells of a HTML table Quote Link to comment https://forums.phpfreaks.com/topic/16238-php-and-mysql-help/#findComment-67270 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.