Jump to content

PHP and MYSQL help


anthonydamasco

Recommended Posts

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]
Link to comment
Share on other sites

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]
Link to comment
Share on other sites

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 work

i get this error, "Unknown column 'id' in 'where clause'"
Link to comment
Share on other sites

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]
Link to comment
Share on other sites

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
Link to comment
Share on other sites

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

?>[/code]
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.