Jump to content


Photo

PHP and MYSQL help


  • Please log in to reply
8 replies to this topic

#1 anthonydamasco

anthonydamasco
  • Members
  • PipPipPip
  • Advanced Member
  • 92 posts

Posted 01 August 2006 - 07:18 PM

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

<?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']);
}


?>


#2 king arthur

king arthur
  • Members
  • PipPipPip
  • Advanced Member
  • 335 posts
  • LocationUK HQ

Posted 01 August 2006 - 07:24 PM

What is the name of your table, what are the column names and which row do you want the data from?
Sir Isaac Newton said "If I have seen farther, it is by standing on the shoulders of giants". But it is not recorded as to whether he said it before or after he was hit on the head by a falling apple.

#3 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 01 August 2006 - 07:26 PM

Here is a quick example:
<?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>';

?>

Make sure you change tbl_name to the actual table you are going to be querying in the accu database. Also change id_field field with the name of the field that contains the id.

Also you might want to go through the tutorials over at php-mysql-tutorials.com

#4 anthonydamasco

anthonydamasco
  • Members
  • PipPipPip
  • Advanced Member
  • 92 posts

Posted 01 August 2006 - 07:27 PM

well I'll show you what i got so far

<?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');


?>

This is what someone else told me to use, but it doesnt work

i get this error, "Unknown column 'id' in 'where clause'"

#5 king arthur

king arthur
  • Members
  • PipPipPip
  • Advanced Member
  • 335 posts
  • LocationUK HQ

Posted 01 August 2006 - 07:28 PM

Then tell us what your column names are.
Sir Isaac Newton said "If I have seen farther, it is by standing on the shoulders of giants". But it is not recorded as to whether he said it before or after he was hit on the head by a falling apple.

#6 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 01 August 2006 - 07:32 PM

Okay thats fine. Change:
$my_row = mysql_fetch_array($result, MYSQL_ASSOC) or die ( mysql_error() );
print_r($my_row);
with:
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>';


#7 anthonydamasco

anthonydamasco
  • Members
  • PipPipPip
  • Advanced Member
  • 92 posts

Posted 01 August 2006 - 07:34 PM

My Cols


orderid - key
usedbefore
nearestlocation
companyname
firstname
lastname
department
phone
fax
address
addresstwo
city
state
country
zip
positiontype
positionclassification
positiontitle
employeesneeded
timeneeded
startdate
workinghours
workAddress
workaddresstwo
workcity
workstate
workzip
positiondescription
skillsrequired
educationrequired
additionalrequirements

#8 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 01 August 2006 - 07:36 PM

Please read my thread above. This is what your code should be:
<?php
error_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>';

?>


#9 anthonydamasco

anthonydamasco
  • Members
  • PipPipPip
  • Advanced Member
  • 92 posts

Posted 01 August 2006 - 07:38 PM

ok it works now how to i get

http://www2.accustaf...rrform.php?id=1

into a table?




let me rephrase that, I need to be able to show this content in differant cells of a HTML table




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users