Current location: Hot Scripts Forums » Programming Languages » PHP » Whats going wrong here?


Whats going wrong here?

Reply
  #1 (permalink)  
Old 06-23-04, 05:59 AM
Tyreal Tyreal is offline
Newbie Coder
 
Join Date: Jan 2004
Location: UK
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Whats going wrong here?

We have a script that soeone else wrote and ive been asked to amend it to display something queried froma database

however im totally new to php and its just totally over my head :/

heres the script:


<HTML>
<HEAD>
<TITLE>Time Sheet Analysis - Menu -</TITLE>
</HEAD>
<BODY><BR>
<CENTER><h2>
<?PHP
// Connect information.
include("dataconnect.inc");

// get username from cookie
$username = $_COOKIE['username'];
$userid = @current(mysql_fetch_row(mysql_query("SELECT userid FROM users WHERE username = '$username'")));

// DB connection.
mysql_connect($host, $user, $pwd) || die (mysql_error());
mysql_select_db($dbase);

//query database for fullname
$fullname = @current(mysql_fetch_row(mysql_query("SELECT fullname FROM users WHERE username = '$username'")));

print("$fullname");



?>
</h2></CENTER>
<BR>
<H2><CENTER><U>Please select option</U></CENTER></H2>
<BR><BR>
<CENTER><A HREF="chkjobstatus.php"> NEW JOB</A></CENTER><BR>
<CENTER><A HREF="chkjobstatusclose.php"> CLOSE JOB</A></CENTER><BR>
<CENTER><A HREF="showcurrent.php"> SHOW CURRENT JOB</A></CENTER><BR>
<center>

<?php
//Get todays job
$todaysdate = date("Y-m-d");

//Select all data concerning jobs for the day
$showqry = "SELECT distinct job, starttime, endtime, cadnum, cadprefixname
FROM jobstatus, time, job, cads, cadprefix
WHERE job.jobstatid = jobstatus.jobstatid
AND job.timeid = time.timeid
AND cads.cadprefixid = cadprefix.cadprefixid
AND cads.cadid = job.cadid
AND userid = '$userid' AND jobdate = '$todaysdate' ORDER BY starttime DESC";

$showrlt = mysql_query($showqry);

print($showrlt)
?>


</center><br>
<CENTER><A HREF="http://cgi.economatics.force9.co.uk/php/timesheet/index.php"> EXIT</A></CENTER><BR>
<BR>

</BODY>
</HTML>

the 2nd part of the script with the php in is the part thats not working eevn with the dbase connection addded in

just comes up with resource id #5

any help for a n00b please
Reply With Quote
  #2 (permalink)  
Old 06-23-04, 08:11 AM
<?Wille?> <?Wille?> is offline
Junior Code Guru
 
Join Date: Jan 2004
Location: Helsinki, Finland
Posts: 666
Thanks: 0
Thanked 0 Times in 0 Posts
im not sure about that || in connection.. but the problem is that you cant echo (or print) the query..
change the print to this and you should get otherkind of output
PHP Code:

while ($r mysql_fetch_array($showrlt)) {

$disc $r['distinct job']; // it would be wise to use htmlspecialchars($r['distinct job'])
$start $r['starttime'];
$end $r['endtime'];
$cadn $r['cadnum'];
$cadpre $r['cadprefixname'];
echo(
$start." ".$end." ".$cadn." ".$cadpre."<br>"); 
Reply With Quote
  #3 (permalink)  
Old 06-24-04, 03:10 AM
Tyreal Tyreal is offline
Newbie Coder
 
Join Date: Jan 2004
Location: UK
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
well the first part of the php works fine its the second part that doesnt ill give it a try thanks
Reply With Quote
  #4 (permalink)  
Old 06-26-04, 01:44 AM
blaw's Avatar
blaw blaw is offline
Junior Code Guru
 
Join Date: Dec 2003
Location: Vancouver, BC, Canada
Posts: 550
Thanks: 0
Thanked 0 Times in 0 Posts
Hello,

This part of your script:

PHP Code:

 $showrlt mysql_query($showqry);


print(
$showrlt
mysql_query(), when used for an SQL statement that returns rows, will return the resouce, and this is not something you can just echo/print, because there could be more than one rows/fields returned, and you want to modify/layout them most likely.

You can use mysql_fetch_array(), mysql_fetch_row(), or mysql_fetch_assoc() to get the resource (results of the query) into an array row by row. After that, you can echo each value according to your needs. For more info about those functions, the very best place with examples would be here:

http://ca2.php.net/mysql-fetch-array
http://ca2.php.net/mysql-fetch-row
http://ca2.php.net/mysql-fetch-assoc

Good luck then!
__________________
Blavv =|
Reply With Quote
  #5 (permalink)  
Old 06-28-04, 05:05 AM
Tyreal Tyreal is offline
Newbie Coder
 
Join Date: Jan 2004
Location: UK
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
hehe i will try thankyou, ima total noob dropped in at the deep end so....

i will try and sort it, as all it does is bring a row back sooo

thanks for the help
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
This is a very simple script that wont work..Please tell me what is wrong with it. ^^ fusion Script Requests 1 06-03-04 10:19 AM
Ok, what's wrong? Please help UVL PHP 10 04-29-04 09:38 AM
PHP email script problems (bounces go to wrong address). MTO PHP 1 04-28-04 11:13 PM
What have I done wrong now??? DAL Perl 4 11-24-03 06:26 PM
something wrong with this code superman PHP 3 07-06-03 10:55 PM


All times are GMT -5. The time now is 05:06 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.