PHP - Query - Returning 1 Row
SELECT i.item_id, i.title, i.price, i.p_and_p, SUM(i.price + i.p_and_p) AS `total_price`, i.listing, i.condition, i.start_date_time, i.listing_duration, CONVERT_TZ(DATE_ADD(i.start_date_time, INTERVAL concat(i.listing_duration) DAY), '+00:00', u.time_zone) AS `end_date_time` FROM items i LEFT JOIN sub_categories sc ON sc.sub_category_id = i.sub_category_id LEFT JOIN categories c ON c.name = 'test' JOIN users u WHERE u.username = 'Destramic' AND i.start_date_time < NOW() AND DATE_ADD(i.start_date_time, INTERVAL concat(i.listing_duration) DAY) >= NOW()I'm having a problem with my query returning more than 1 rows...I've even copied the row which is returning to see if that'll return 2 rows but it doesn't can anyone explain why this is happening please? Similar TutorialsWhat would be the correct way to close a mysql query? At current the second query below returns results from the 1st query AND the 2nd query The 3rd query returns results from the 1st, 2nd and 3rd query. etc etc. At the moment I get somthing returned along the lines of... QUERY 1 RESULTS Accommodation 1 Accommodation 2 Accommodation 3 QUERY 2 RESULTS Restaurant 1 Restaurant 2 Restaurant 3 Accommodation 1 Accommodation 2 Accommodation 3 QUERY 3 RESULTS Takeaways 1 Takeaways 2 Takeaways 3 Restaurant 1 Restaurant 2 Restaurant 3 Accommodation 1 Accommodation 2 Accommodation 3 Code: [Select] <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <?php include($_SERVER['DOCUMENT_ROOT'].'/include/db.php'); ?> <title>Untitled Document</title> <style type="text/css"> <!-- --> </style> <link href="a.css" rel="stylesheet" type="text/css" /> </head><body> <div id="listhold"> <!------------------------------------------------------------------------------------------------------------------------------------------------------> <div class="list"><a href="Placestostay.html">Places To Stay</a><br /> <?php $title ="TITLE GOES HERE"; $query = mysql_query("SELECT DISTINCT subtype FROM business WHERE type ='Accommodation' AND confirmed ='Yes' ORDER BY name"); echo mysql_error(); while($ntx=mysql_fetch_row($query)) $nt[] = $ntx[0]; $i = -1; foreach($nt as $value) {$i++; $FileName = str_replace(' ','_',$nt[$i]) . ".php"; $FileUsed = str_replace('_',' ',$nt[$i]); echo "<a href='" . str_replace(' ','_',$nt[$i]) . ".php?title=$title&subtype=$FileUsed'>" . $nt[$i] . "</a>" . "<br/>"; $FileHandle = fopen($FileName, 'w') or die("cant open file"); $pageContents = file_get_contents("header.php"); fwrite($FileHandle,"$pageContents");} fclose($FileHandle); ?> </div> <!------------------------------------------------------------------------------------------------------------------------------------------------------> <div class="list"><a href="Eatingout.html">Eating Out</a><br /> <?php $title ="TITLE GOES HERE"; $query = mysql_query("SELECT DISTINCT subtype FROM business WHERE type ='Restaurant' AND confirmed ='Yes' ORDER BY name"); echo mysql_error(); while($ntx=mysql_fetch_row($query)) $nt[] = $ntx[0]; $i = -1; foreach($nt as $value) {$i++; $FileName = str_replace(' ','_',$nt[$i]) . ".php"; $FileUsed = str_replace('_',' ',$nt[$i]); echo "<a href='" . str_replace(' ','_',$nt[$i]) . ".php?title=$title&subtype=$FileUsed'>" . $nt[$i] . "</a>" . "<br/>"; $FileHandle = fopen($FileName, 'w') or die("cant open file"); $pageContents = file_get_contents("header.php"); fwrite($FileHandle,"$pageContents");} fclose($FileHandle); ?> </div> <!------------------------------------------------------------------------------------------------------------------------------------------------------> <div class="list"><a href="Eatingin.html">Eating In</a><br /> <?php $title ="TITLE GOES HERE"; $query = mysql_query("SELECT DISTINCT subtype FROM business WHERE type ='Takeaways' AND confirmed ='Yes' ORDER BY name"); echo mysql_error(); while($ntx=mysql_fetch_row($query)) $nt[] = $ntx[0]; $i = -1; foreach($nt as $value) {$i++; $FileName = str_replace(' ','_',$nt[$i]) . ".php"; $FileUsed = str_replace('_',' ',$nt[$i]); echo "<a href='" . str_replace(' ','_',$nt[$i]) . ".php?title=$title&subtype=$FileUsed'>" . $nt[$i] . "</a>" . "<br/>"; $FileHandle = fopen($FileName, 'w') or die("cant open file"); $pageContents = file_get_contents("header.php"); fwrite($FileHandle,"$pageContents");} fclose($FileHandle); ?> </div> <!------------------------------------------------------------------------------SKILLED TRADES BELOW---------------------------------------------------> <div class="list"><a href="Skilledtrades.html">Skilled Trades</a><br/> <?php $title ="TITLE GOES HERE"; $query = mysql_query("SELECT DISTINCT subtype FROM business WHERE type ='Skilled Trades' AND confirmed ='Yes' ORDER BY name"); echo mysql_error(); while($ntx=mysql_fetch_row($query)) $nt[] = $ntx[0]; $i = -1; foreach($nt as $value) {$i++; $FileName = str_replace(' ','_',$nt[$i]) . ".php"; $FileUsed = str_replace('_',' ',$nt[$i]); echo "<a href='" . str_replace(' ','_',$nt[$i]) . ".php?title=$title&subtype=$FileUsed'>" . $nt[$i] . "</a>" . "<br/>"; $FileHandle = fopen($FileName, 'w') or die("cant open file"); $pageContents = file_get_contents("header.php"); fwrite($FileHandle,"$pageContents");} fclose($FileHandle); ?> </div> Greetings all! I've been working on a project for about a week now and everything had been going fine until this evening. I'm querying a single row from a user information table based on the userID and doing various things based off of the information that is returned. For whatever reason, the query is not returning all of the information anymore. Code follows: Code: [Select] $userToEdit = mysqli_real_escape_string($GLOBALS['link'], $_POST['userToEdit']); $userSQL = "SELECT fName, lName, email, volunteer, staff, admin, active, volunteerID FROM userinfo WHERE userID=" . $userToEdit; $result = mysqli_query($GLOBALS['link'], $userSQL); if (!$result) { $message = 'There was an error retrieving the user information from the database.'; include '../html/error.html.php'; exit(); } $editInfo = mysqli_fetch_assoc($result); The strange part is that the database i'm querying is located on my remote host(GoDaddy). When I run the app from my local Apache server and query the remote DB, everything works fine, however, when I upload the files to my host, not all of the information is being returned. For example, using the print_r() function while on my local host, i get: Code: [Select] Array ( [fName] => Taylor [lName] => Hughes [email] => taylor@gmail.com [volunteer] => 1 [staff] => 0 [admin] => 0 [active] => 1 [volunteerID] => 13 ) But when I execute the app on my remote host, the print_r() function outputs: Code: [Select] Array ( [fName] => Taylor [lName] => Hughes [email] => taylor@gmail.com [volunteer] => [staff] => [admin] => [active] => [volunteerID] => 13 ) I'm not sure why this is happening but it is affecting multiple queries and subsequently multiple forms and functionality in different parts of the application. Any thoughts or suggestions would be greatly appreciated. I've browsed around for about an hour with no luck. I'm writing in PHP 5.3 and the remote MySQL DB is version 5.0 Oh! And if it helps, I just came to the realization that all the items not being returned are of the BIT data type in the tables. Hello all, Trying to figure out how to display database results so that they are numbered (for editing and deletion purposes). I want to be able to edit the message text and update the database information with the UPDATE command, but have not gotten that far yet. Current problem is that I am returning no results. Here is my script: Code: [Select] <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>My Profile</title> <link href="loginmodule.css" rel="stylesheet" type="text/css" /> </head> <body> <h1>My Profile </h1> <a href="member-index.php">Home</a> | <a href="member-profile.php">My Profile</a> | Update Posts | <a href="logout.php">Logout</a> <br /><br /> <?php $subject = $_POST['subject']; $message_text = $_POST['message_text']; //Connect to mysql server $link = mysql_connect('XXXXXX', 'XXXXXX', 'XXXXXX'); if(!$link) { die('Failed to connect to server: ' . mysql_error()); } //Select database $db = mysql_select_db('ryan_iframe'); if(!$db) { die("Unable to select database"); } // validate incoming values $subject = (isset($_GET['subject'])) ? (int)$_GET['subject'] : 0; $message_text = (isset($_GET['message_text'])) ? (int)$_GET['message_text'] : 0; ob_start(); $id = $_GET['SUBJECT']; $query = sprintf( " SELECT SUBJECT, MSG_TEXT, UNIX_TIMESTAMP(MSG_DATE) AS MSG_DATE FROM FORUM_MESSAGE WHERE SUBJECT = '$id' ORDER BY MSG_DATE DESC", DB_DATABASE, DB_DATABASE, $subject, $subject); $result = mysql_query($query) or die(mysql_error()); $num = mysql_numrows($result); mysql_close(); $i = 0; while ($i < $num) { $subject = mysql_result($result, $i, "SUBJECT"); $message_text = mysql_result($result, $i, "MSG_TEXT"); echo '<div style="width: 400px;padding:20px;">'; echo '<table border=0 width="400px">'; echo '<tr>'; echo '<td style="vertical-align:top;width:auto;">'; echo 'Date: '; echo '</td>'; echo '<td style="vertical-align:top;width:320px;">'; echo date('F d, Y', $row['MSG_DATE']) . '</td>'; echo '</tr>'; echo '<tr>'; echo '<td style="vertical-align:top;width:auto;">'; echo 'Subject: '; echo '</td>'; echo '<td style="vertical-align:top;width:320px;">'; echo '<div>' . htmlspecialchars($row['SUBJECT']) . '</div>'; echo '</td>'; echo '</tr>'; echo '<tr>'; echo '<td style="vertical-align:top;width:auto;">'; echo 'Message: '; echo '</td>'; echo '<td style="vertical-align:top;width:320px;">'; echo '<div>' . htmlspecialchars($row['MSG_TEXT']) . '</div>'; echo '</td>'; echo '</tr>'; echo '<tr>'; echo '<td style="vertical-align:top;width:auto;">'; echo '</td>'; echo '<td style="vertical-align:top;width:320px;text-align:center;">'; echo '<form method="post">'; echo '<input type="hidden" name="update" value="true" />'; echo '<input type="submit" value="Update" />'; echo ' '; echo '<input type="hidden" name="delete" value="true" />'; echo '<input type="submit" value="Delete" />'; echo '</form>'; echo '</td>'; echo '</tr>'; echo '</table>'; echo '<br />'; echo '<hr />'; echo '</div>'; ++$i; } ?> </body> </html> Thanks in advance. Ryan Originally, I would get both, and unfortunately would inconsistently use both. Then, I wanted more consistently, so configured php.ini to only return objects as I felt accessing them was more concise. And then later, I found myself needing arrays more often, and initially would just typecast them to arrays but eventually my standard was to set the PDO's fetch style to an array. And now I find myself almost always explicitly requesting arrays and occasionally requesting columns or named values. Do you configure ATTR_DEFAULT_FETCH_MODE, and if so to what? PS. Anyone use FETCH_CLASS, FETCH_INTO or FETCH_NUM? If so, what would be a good use case? I'm having trouble with a simple SELECT query. I just cannot figure out what the problem is... <?php //Include database connection details include 'login/config.php'; //Connect to mysql server $link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD); if(!$link) { die('Failed to connect to server: ' . mysql_error()); } //Select database $db = mysql_select_db(DB_DATABASE); if(!$db) { die("Unable to select database"); } $qry="SELECT * FROM members"; $result = mysqli_query($link, $qry); echo "<table>"; while($row = mysqli_fetch_array($result, MYSQL_ASSOC)) { $getid = ($row['member_ID']); $firstname = ($row['firstname']); $lastname = ($row['lastname']); $email = ($row['email']); echo "<tr><td>$firstname</td><td>$email</td></tr>"; } echo "</table>"; ?> I know I have a connection to the DB, and I know that the query will return values as I have tested in in phpmyadmin. Can anyone see anything obvious I am missing? Thanks Ok, this may be just because I have been programming all day and my mind has gone blank (happens alot), but this is my PHP script: Code: [Select] <?php $query_distinct_item_types = mysql_query("SELECT DISTINCT name FROM item_types"); while($item_types = mysql_fetch_array($query_distinct_item_types)){ $distinct_item_types[] = $item_types['name']; } foreach($distinct_item_types as $item){ $query_item_total = mysql_query("SELECT item_type, SUM(price) WHERE item_type='$item' FROM costs GROUP BY item_type"); while($item_total = mysql_fetch_array($query_total_price)){ $item_totals[] = $item_total['SUM(price)']; } } $item_summery = $item_totals; ?> $item_summery which is = to $item_totals is returning null, any idea's? Moodle 2.5 *nix server Theme: Essential ---------------------- Hi Folks I have a small mind bender in how php is returning results from a mysql query. There are two issues: 1) The mysql query from phpmyadmin is correct, while the php function that handles the query from the website is not. 2) It takes a very long time to run this query with php, 30 seconds to over a minute. Phpmyadmin is rather quick (Query took 0.0239 seconds). The query is: SELECT u.firstname AS 'Name' , u.lastname AS 'Surname', c.shortname AS 'Course', ( CASE WHEN gi.itemname LIKE '%summative%' THEN 'SUMMATIVE' WHEN gi.itemname LIKE '%formative 2%' THEN 'FORMATIVE 2' ELSE 'MC' END) AS 'Assessment', from_unixtime(gi.timemodified, '%d/%m/%y') AS 'Date', IF (ROUND(gg.finalgrade / gg.rawgrademax * 100 ,2) > 70,'Yes' , 'No') AS Pass, ROUND(gg.finalgrade / gg.rawgrademax * 100 ,2) AS 'Mark', ROUND(gg.finalgrade / gg.rawgrademax * 100 ,2) AS 'Mark' FROM mdl_course AS c JOIN mdl_context AS ctx ON c.id = ctx.instanceid JOIN mdl_role_assignments AS ra ON ra.contextid = ctx.id JOIN mdl_user AS u ON u.id = ra.userid JOIN mdl_grade_grades AS gg ON gg.userid = u.id JOIN mdl_grade_items AS gi ON gi.id = gg.itemid JOIN mdl_course_categories AS cc ON cc.id = c.category WHERE gi.courseid = c.id AND gi.itemname != 'Attendance' AND u.firstname LIKE '%03%' AND gi.itemname LIKE '%mative%' ORDER BY `Name` , `Surname` , `Course`, `Assessment` ASCWhen I run the query in phpmyadmin , it gives back; Name Surname Category Module Course Assessment Date Competent Mark G03 Itumeleng Velmah Mokwa Fundamentals Communications CO1 119472 FORMATIVE 2 07/04/14 Yes 100.00 G03 Itumeleng Velmah Mokwa Fundamentals Communications CO1 119472 SUMMATIVE 07/04/14 Yes 100.00 G03 Itumeleng Velmah Mokwa Fundamentals Communications CO2 119457 FORMATIVE 2 05/04/14 Yes 100.00 G03 Itumeleng Velmah Mokwa Fundamentals Communications CO2 119457 SUMMATIVE 05/04/14 Yes 88.00 G03 Lally Sheila Mokane Fundamentals Communications CO1 119472 FORMATIVE 2 07/04/14 NYC 59.00 G03 Lally Sheila Mokane Fundamentals Communications CO1 119472 SUMMATIVE 07/04/14 Yes 90.00 G03 Lally Sheila Mokane Fundamentals Communications CO2 119457 FORMATIVE 2 05/04/14 Yes 100.00 G03 Lally Sheila Mokane Fundamentals Communications CO2 119457 SUMMATIVE 05/04/14 Yes 98.00And it is perfect so I have no issues with that. Now in php I call; function print_overview_table_groups($COURSE, $choosegroup, $fromdate, $todate, $numarray) { global $DB; //check data if(!$choosegroup){ die('No Records To Display.'); } $thisgroup = $numarray[$choosegroup]; $sql = "SELECT DISTINCT u.firstname AS 'Name' , u.lastname AS 'Surname', (CASE WHEN cc.parent = '2' THEN 'Fundamentals' WHEN cc.parent = '3' THEN 'Core' WHEN cc.parent = '4' THEN 'Elective' END) AS 'Category', cc.name AS 'Module', c.shortname AS 'Course', (CASE WHEN gi.itemname LIKE '%summative%' THEN 'SUMMATIVE' WHEN gi.itemname LIKE '%formative 2%' THEN 'FORMATIVE 2' ELSE 'MC' END) AS 'Assessment', from_unixtime(gi.timemodified, '%d/%m/%y') AS 'Date', IF (ROUND(gg.finalgrade / gg.rawgrademax * 100 ,2) > 70,'Yes' , 'NYC') AS Competent, ROUND(gg.finalgrade / gg.rawgrademax * 100 ,2) AS 'Mark' FROM mdl_course AS c JOIN mdl_context AS ctx ON c.id = ctx.instanceid JOIN mdl_role_assignments AS ra ON ra.contextid = ctx.id JOIN mdl_user AS u ON u.id = ra.userid JOIN mdl_grade_grades AS gg ON gg.userid = u.id JOIN mdl_grade_items AS gi ON gi.id = gg.itemid JOIN mdl_course_categories AS cc ON cc.id = c.category WHERE gi.courseid = c.id AND gi.itemname != 'Attendance' AND u.firstname LIKE '%03%' AND gi.itemname LIKE '%mative%' ORDER BY `Name` , `Surname` , `Course`, `Assessment` ASC"; return $DB->get_records_sql($sql); }This is returned to the index.php page from the function call; $lists = print_overview_table_groups($COURSE, $choosegroup, $fromdate, $todate, $numarray); print "<pre>"; print_r($lists); print "</pre>";The result is baffling... Array ( [G03 Itumeleng] => stdClass Object ( [name] => G03 Itumeleng [surname] => Mokwa [category] => Fundamentals [module] => Communications [course] => CO2 119457 [assessment] => SUMMATIVE [date] => 05/04/14 [pass] => Yes [mark] => 88.00 ) [G03 Lally] => stdClass Object ( [name] => G03 Lally [surname] => Mokane [category] => Fundamentals [module] => Communications [course] => CO2 119457 [assessment] => SUMMATIVE [date] => 05/04/14 [pass] => Yes [mark] => 98.00 ) )I only get one record for each student. Can anyone help me solve this? Regards Leon Hi I am new to php, I am trying to capture the url and place into a variable but I only get the 1st digit to show, I just cant see what I am doing wrong. Sorry to ask such a basic question but I just can't work it out, I have attached a screen shot of all me code, your help would be very very much appreciated. i am having issues returning all sent messages. it will only return one for some reason. Code: [Select] //If there are sent messages, display them if ($row = mysql_num_rows($result) > 0) { $row = mysql_fetch_array($result) or die(mysql_error()); //Open table and create headers echo "<table border=\"1\">\n"; echo " <tr>\n"; echo " <th>Recipient</th>\n"; echo " <th>Subject</th>\n"; echo " </tr>\n"; while(mysql_fetch_array($result)) { //Show messages $userIDTo = $row['userIDTo']; // Get the recipient's ID number $recipient = checkRecipient($userIDTo); // Get the sender's Username $messageID = $row['ID']; echo " <tr>\n"; echo " <td>{$recipient}</td>\n"; echo " <td><a href='messageDetails.php?messageID=$messageID' target='_blank'>{$row['subject']}</a></td>\n"; echo " <tr>\n"; } thanks in advance. Ok I have this code retrieving information from mysql: if (isset($memid)) { $query_meminfo = "SELECT * FROM ".MEMBER_PROFILE_TABLE." WHERE `user_id`=".$memid; $query_result = mysql_query($query_meminfo, $db); $MemName = mysql_result($query_result, 0, 'display_name'); $MemGroup = mysql_result($query_result, 0, 'Group'); $LevelQuery = "SELECT group_level FROM ".MEMBER_GROUPS." WHERE group_id='".$MemGroup."'"; $LevelResult = mysql_result(mysql_query($LevelQuery, $db), 0, 'group_level'); $MemLevel = intval($LevelResult); } It is definitely retrieving the correct info as it is correctly checking member levels to display certain information. Part 2 of code: <table width="100%" id="userlinks" cellspacing="6"> <tr> <td>Welcome <?php if (isset($MemName)) { Echo $MemName + " "; ?> (<a href="index.php?act=logout">Logout</a> <?php if ($MemLevel >= 9000) { echo " | <a href='admin.php'>Admin CP</a>"; } ?> ) <?php } Else { ?> Guest (<a href="index.php?act=login">Login</a> | <a href="index.php?act=register">Register</a>) <?php } ?> </td> </tr> </table> For some reason, instead of displaying the person's display name it is just displaying the number 0. Hi all. I'm having a bit of trouble with my script. I can't get "getDirectoryListings()" to return what folders are inside of #SharedObjects Here's my 2 files, 1 is sollib.php, the other is solindex.php. Code: [Select] solindex.php: <?php require('sollib.php'); $shell= new COM('WScript.Shell'); $data=$shell->regRead('HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\ProgramFilesDir'); $regval = trim($data, "Program Files"); if(getenv('AppData')!=''){ $filename = getenv('AppData')."\\Macromedia\\FlashPlayer\\#SharedObjects\\".getDirectoryListings(); die($filename); } ?> sollib.php: <?php die(getDirectoryListings()); function getDirectoryListings() { $final = ""; $filename = getenv('AppData')."\\Macromedia\\FlashPlayer\\#SharedObjects\\"; if ($handle = opendir($filename)) { while (false !== ($file = readdir($handle))) { if(($file != '.') && ($file != '..')) { if(!strpos($file,'.')) { if ($handle2 = opendir($filename.$file)) { while (false !== ($file2 = readdir($handle2))) { die($file2); if(($file2 != '.') && ($file2 != '..')) { $final = $filename."$file\\$file2\\".get_files($file2); die($final); if($file2 == 'www.xatech.com'){ die('files: '.get_files($file2)); } } } } }else{ $final = $file; } } } closedir($handle); } return $final; } function get_files($dir){ //path to directory to scan $directory = $dir; //get all sol files with a .sol extension. $file11 = glob("" . $directory . "*.sol"); //print each file name foreach($file11 as $files10){ $final = $files10; die($final); } } ?> How would i return the id in the echo of this post: $query = "INSERT INTO jobs SET agent = '".mysql_real_escape_string($agent)."', title = '".mysql_real_escape_string($title)."', location = '".mysql_real_escape_string($location)."', salary_from = '".$salary_from."', salary_to = '".$salary_to."', frequency = '".$frequency."', jobtype='".$jobtype."', description='".$description."', email = '".$email."', created_at = '".$created_at."', closing_date ='".$closing_date."', categories = '".$categories."', sectors = '".$sectors."', ref='".$ref."'"; if(mysql_query($query)) { echo "Job inserted!"; } else { die(mysql_error()); } Thanks for the help guys My aim is for this what if the table is empty which means no results will be retrieved in the first query then I want it to repeat the $testArray as "TBD" as well. Code: [Select] function getTop5() { $this->db->select('character1_id, character2_id, character3_id, character4_id, character5_id'); $this->db->from('site_top5'); $this->db->where('status_id', '1'); $this->db->order_by('id', 'desc'); $query = $this->db->get(); $row = $query->row(); $ids = array( $row->character1_id, $row->character2_id, $row->character3_id, $row->character4_id, $row->character5_id ); $testArray = array(); foreach ($ids as $id) { if($id !== "0") { $this->db->select('character_name'); $this->db->from('characters'); $this->db->where('id', $id); $query = $this->db->get(); $row = $query->row(); $testArray[] = $row->character_name; } else { $testArray[] = "TBA"; } } return $testArray; } Hey there, Now I was curious if there was a way I could return an array in my function like the following, I currently get a error though: Code: [Select] Catchable fatal error: Object of class panel_accounts could not be converted to string in C:\wamp\www\X-HostLTD - Panel\PanelFrontend\index.php on line 21 But can you only return strings?. Here is the function that it errors on: function returnAccountInformation($AccountID) { return mysql_fetch_array(mysql_query("SELECT * FROM ****_***** WHERE *****_***** = '".mysql_escape_string($AccountID)."'")); } Could somebody help me on the matter?, Thank you. P.S sorry for staring out the table names but I don't really want people knowing my database structure hehe. Hi All Please take a look at the code below. I am sucessfully accessing a database and pulling the details through into a HTML form with a drop down. However I then want to use a variable (test) in another page. However I cannot get the variable userrow['userid'] to send a value to my getquiz.php. What am I doing wrong? <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML> <HEAD> <TITLE> New Document </TITLE> <META NAME="Generator" CONTENT="EditPlus"> <META NAME="Author" CONTENT=""> <META NAME="Keywords" CONTENT=""> <META NAME="Description" CONTENT=""> </HEAD> <?php include_once "db.inc.php"; ?> <body> <form action="getquiz.php" method="GET"> <tr><td class="title">Please Select User</td> <td><select name="test"> <?php $courseid = mysqli_query($link, 'SELECT id FROM mdl_quiz WHERE course = "225"; '); if (!courseid) { $error = ' Error fetching course id: ' . mysqli_error($link); include 'error.html.php'; exit(); } else { while($row = mysqli_fetch_array($courseid)) { $user = mysqli_query($link, 'SELECT userid FROM mdl_quiz_attempts WHERE quiz =' . $row['id']); while ($userrow = mysqli_fetch_array($user)) { $names = mysqli_query($link, 'SELECT firstname,lastname FROM mdl_user WHERE id=' . $userrow['userid']); while ($usernames = mysqli_fetch_array($names)) {?> <option value="<?php $userrow['userid']?>"> <?php echo $usernames ['firstname'] . " " . $usernames['lastname'] . $userrow['userid']; ?> </option> <?php } } } } ?> </select> </td></tr> <center><input type="submit" value="Submit"></center> </table> </form> </body> </html> hello, anybody able to help me with why this is only returning the first staff member's hours? Code: [Select] <?php if(isset($_POST['view'])) { $y3=$_POST['y']; $m3=$_POST['m']; $d3=$_POST['d']; $pdate=$y3."-".$m3. "-".$d3; $pdate1 = date( 'D M j', strtotime($pdate) ); } else { $pdate = date('Y-m-d', strtotime("-1 day") ); $pdate1 = date( 'D M j', strtotime($pdate) ); } echo "<table border='1' style='border-collapse: collapse' bordercolorlight='#000000' bordercolordark='#000000' width='98%' align='center'>"; echo "<tr><td width='100%' colspan='9' align='center'><b>Timesheets For $pdate1</b></td></tr>"; $result = mysql_query("SELECT * FROM staff ORDER BY name"); while($row = mysql_fetch_array($result)) { $eid=$row['eid']; $name=$row['name']; echo "<tr>"; echo "<td align='left' colspan='9'><b>" . $name . "</b></td>"; echo "</tr>"; echo "<tr> <th align='center'>Date</th> <th align='center'>Job Number</th> <th align='center' width='30%'>Service Report</th> <th align='center'>Sign In Time</th> <th align='center'>Sign Out Time</th> <th align='center'>Lunch</th> <th align='center'>Time Billed</th> <th align='center'>Estimated</th> </tr>"; $result3 = mysql_query("SELECT * FROM timesheet WHERE date = '$pdate' AND eid = '$eid'"); $talltime = 0; while($row3 = mysql_fetch_array($result3)) { $tid=$row3['id']; $tdate=$row3['date']; $tjobnumber=$row3['jobnumber']; $teid=$row3['eid']; $tdescription=$row3['description']; $tsignin=$row3['start']; $tfinish=$row3['finish']; $tlunch=$row3['lunch']; $tkms=$row3['kms']; $tschednum=$row3['schednum']; $tdate1 = date( 'M j, Y', strtotime($tdate) ); $tsignin1 = date( 'g:i a', strtotime($tsignin) ); $tfinish1 = date( 'g:i a', strtotime($tfinish) ); if( empty($tfinish) ) { $tfinish2="<i>In Progress"; } else { $tfinish2="$tfinish1"; } $shortid=substr($tjobnumber, 5, -1); //remove the first 5 characters and minus the last character $result = mysql_query("SELECT * FROM jobs WHERE id = '$shortid'"); while($row = mysql_fetch_array($result)) { $jstatus=$row['status']; } $result4 = mysql_query("SELECT * FROM schedule WHERE id = '$tschednum'"); while($row4 = mysql_fetch_array($result4)) { $sid=$row4['id']; $sdate=$row4['date']; $seid=$row4['eid']; $sjobnumber=$row4['jobnumber']; $sstarttime=$row4['starttime']; $sstatus=$row4['status']; $setime=$row4['etime']; } $log_in_time_string = strtotime($tsignin); $log_out_time_string = strtotime($tfinish); $difference_in_seconds = ($log_out_time_string - $log_in_time_string); $tbilled = ($difference_in_seconds / 3600); if($tbilled < 0) { $tbilled1 = $tbilled + 24; } else { $tbilled1=$tbilled; } $tbilled2 = number_format(round($tbilled*4)/4,2); $tbilled3 = $tbilled2 - $tlunch ; $talltime += $tbilled3; echo "<tr>"; echo "<td align='center'>" . $tdate1 . "</td>"; echo "<td align='center'>" . $tjobnumber . "</td>"; echo "<td align='center'>" . $tdescription . "</td>"; echo "<td align='center'>" . $tsignin1 . "</td>"; echo "<td align='center'>" . $tfinish2 . "</td>"; echo "<td align='center'>" . $tlunch . " hour</td>"; echo "<td align='center'>"; if ($tbilled3 > $setime ) { echo "<font color='red'><b>*** " . $tbilled3 . " hours ***</b></font>"; } else { echo "" . $tbilled3 . " hours"; } echo "</td>"; echo "<td align='center'>" . $setime . " hours</td>"; echo "</tr>"; } echo "<tr>"; echo "<td colspan='6' align='right'><b>Totals :</td>"; echo "<td align='center' colspan='2'>"; if ($talltime > "8" ) { echo "<font color='red'><b>*** " . $talltime . " hours ***</b></font>"; } elseif ($talltime < "0" ) { echo "<font color='red'><b>Not Signed Out</b></font>"; } else { echo "" . $talltime . " hours"; } echo "</td>"; echo "</tr>"; echo "<tr>"; echo "<td align='center' colspan='8' bgcolor='#D9FFD9'><hr></td>"; echo "</tr>"; } echo "</table>"; include 'close.php'; ?> I'm trying to get this to either show "Final" or "Final Overtime" but it just continues to show "Final" even when the XML key value says Overtime...
What am I missing here?
Thank you!
Hello, I am trying to implement error proofing to a log in script. But, I cannot get it to work? I have no idea what is going on, or why it doesn't work like I expect it to. I have tried everything, please advise. This is the method I am calling: Code: [Select] public function i_exist($this_username) { //$host_array = null; //$host_array = $this->collection->findOne(array("Username" => $this_username)); //if ($host_array['Username'] = $this_username) //{ return true; //} //return false; } This is where I am calling it: Code: [Select] if (!empty($_POST['Username'])) { $host = new Host(); $event = new Event(); if ($host->i_exist($_POST['Username'])) { header("Location: http://www.drink-social.com/error.php?login=duplicate"); } It is supposed to check the database and see if that username is already in use. But it never directs to the error page? I have even tried commenting everything out and returning true, and returning 1. Nothing? Any advice? Okay, I had a similar problem before.
$users = mysql_query("SELECT * FROM users"); while($users = mysql_fetch_assoc($users)){ echo "<tr><td><p><a href='users.php?id={$users['user_id']}'>{$users['user_name']}</a></p></td><td>{$users['user_clan']}</td><td>{$users['troop_donations']}</td></tr>"; } Hello. I am trying to pass along a variable in an email auto response ($park), however if the variable is 2 words then it only passes along the first word. Any info would be great. Code: [Select] <?php $to = "$email"; $subject = "Event Signup Confirmation"; $message = "Hello $firstname! Thank you for signing up to work the $park event. Someone will contact you shortly. Event Information Park: $park Date: $orderdate Time: $hour:$min $ampm Description: $description Crew Leader: $leader"; $from = "guy@xxxx.com"; $headers = "From: $from"; mail($to,$subject,$message,$headers); echo "Thank you for signing up. You will receive an email shortly letting you know event details and who your crew leader is."; ?> |