Click to See Complete Forum and Search --> : PHP Hiccup accessing MySQL


nko
01-03-2004, 06:40 AM
I know I'm just doing something wrong. I'm trying to select data and print it out to the screen. Here's what I've got:

<?php
session_start();

include_once('include/header');

mysql_connect('localhost', $_SESSION[user_name], $_SESSION[password]);

mysql_select_db('records');

$query="select insert_date from jobs where job_num=\"$_POST[job_num]\"";

$result=mysql_query($query);

$output=mysql_fetch_array($result);

print("Result: $result<br>Output: $output<br>SQL Query: $query");

include_once('include/footer');
?>

This ends up trying to tell me that $result==Resource id #3 and $output==Array.

What I want to do is pull a date from a table and print it out to the screen, just like that. I know it's just some syntax thing I'm getting wrong, being new to this and all. Thanks!

nko
01-03-2004, 05:53 PM
Alright, figured it out. Instead of printing out the variable returned, you have to print out the first variable in the ARRAY that's returned. It's saying "array" because it's successfully gathering the information... as an array. So when I try to print out the whole array as a single thing, it's spouting that it's an array. Which makes sense, because what the function does is it gets an array. Like the name implies.

If programming / scripting is so frustrating, why do I feel so awesome now!?

So for anyone with a similar problem, all you have to change about the below is:

print("$result");

should be:

print("$result[0]");