BloodyMind Posted November 26, 2008 Share Posted November 26, 2008 What I'm trying to do is fetching project's details into a page, What I get is a record that has nothing to do with the ID i've requested the query to be done on, I've tried to execute the query on phpMyAdmin and it works perfectly, Plus the results execute on the a line good and the other it doesn't I don't have any clue please professional help here is the code: Project's details page(project-details.php?pid=2): <?php require_once('bizlogic/projects.class.php'); require_once('conf/conf.inc.php'); if (is_numeric($_GET['pid'])){ $project = new Projects($db['host'],$db['username'],$db['password'],$db['name']); $projectId = $_GET['pid']; $rows = $project->getProject($projectId); if (!is_array($rows)) { echo $rows; die(); } var_dump($rows); foreach($rows as $row){ $title = 'Catalyst Contractors Inc. | ' . $row['pro_name']; include_once('includes/header.inc.php'); //---------------this following line who is fucking up my life !!!! include_once('includes/sidebar.inc.php'); echo $row['pro_name'] . "<br />"; echo "<h4>" . $row['cat_title'] . ": </h4>"; echo "<table width=\"700\" height=\"248\" border=\"0\" cellpadding=\"2\" cellspacing=\"0\" id=\"proDetails\">"; echo "<tr>"; echo "<td colspan=\"2\" class=\"p\"><img src='" . PROIMG_URL . "/" . $row['pro_photo'] . "' alt='" . $row['pro_name'] . "' width=\"563\" height=\"375\" /></td>"; echo "</tr>"; echo "<tr>"; echo "<td width=\"118\" class=\"p\"><span class=\"p\"><strong>Project Name:</strong></span></td>"; echo "<td width=\"578\"><span class=\"p\">" . $row['pro_name'] . "</span></td>"; echo "</tr>"; echo "<tr>"; echo "<td class=\"p\"><span class=\"p\"><strong>Location:</strong></span></td>"; echo "<td><span class=\"p\">" . $row['city'] . ", " . $row['state'] . "</span></td>"; echo "</tr>"; echo "<tr>"; echo "<td class=\"p\"><span class=\"p\"><strong>Value: </strong></span></td>"; echo "<td><span class=\"p\">" . $row['value'] . "</span></td>"; echo "</tr>"; echo "<tr>"; echo "<td class=\"p\"><span class=\"p\"><strong>Owner:</strong></span></td>"; echo "<td><span class=\"p\">" . $row['owner'] . "</span></td>"; echo "</tr>"; echo "<tr>"; echo "<td class=\"p\"><span class=\"p\"><strong>Type of work:</strong></span></td>"; echo "<td><span class=\"p\">" . $row['type_of_work'] . "</span></td>"; echo "</tr>"; echo "<tr>"; $row['pro_desc'] = nl2br($row['pro_desc']); echo "<td colspan=\"2\" class=\"p descCell\"><p><span class=\"p\">" . $row['pro_desc'] . "</span></p></td>"; echo "</tr>"; echo "</table>"; } ?> here is the code of the method from the class: <?php public function getProject($in_ProjectId){ try { $projectId = intval($in_ProjectId); $getSQL = "SELECT * FROM projects p LEFT JOIN categories c ON p.cat_id = c.cat_id WHERE pro_id = '$projectId'"; $results = $this->conn->query($getSQL); if ($results == FALSE) { throw new Exception('Database Error: Cannot fetch project\'s data.'); } $rows = array(); while ($row = $results->fetch_assoc()){ $rows[] = $row; break; } return $rows; }catch (Exception $e){ return $e->getMessage(); } } ?> sidebar.inc.php: <?php <div id="sidebar1"> <div id="featuredproj"><img src="<?php echo BASE_URL; ?>/images/catalyst_07.jpg" alt="" name="featuredproj" width="152" height="16" id="catalyst_07" /><br /> </div> <br /> <div id="bridge"> <img id="catalyst_11" src="<?php echo BASE_URL; ?>/images/catalyst_11.jpg" width="188" height="64" alt="" /> </div> <br /> <table width="200" border="0" cellspacing="0" cellpadding="1" id="prodTable"> <?php $projects = new projects($db['host'],$db['username'],$db['password'],$db['name']); // 1. first SELECT categories $numOfCategories = $projects->getNumCategories(); for ($i=1;$i<=$numOfCategories;$i++){ $projectRows = $projects->getAllProjectsByCategory($i); if (!is_array($projectRows)) { echo $projectRows; die(); } echo "<tr>\r\n"; echo "<td valign='bottom' align='left'><strong>" . $projectRows[$i-1]['cat_title'] . ":</strong></td>"; echo "</tr>"; echo "<tr>"; echo "<td><form name='form' id='form'>"; echo "<select name=\"jumpMenu\" id=\"jumpMenu\" onchange=\"MM_jumpMenu('parent',this,0)\">"; echo "<option>Select Project</option>"; foreach ($projectRows as $row) { echo "<option value='project-details.php?pid=" . $row['pro_id'] . "'>" . $row['pro_title'] . "</option>"; } echo "</select>"; echo "<br /><br />"; echo "</form></td>"; echo "</tr>"; } ?> </table> <p> </p> <p> </p> </div> <!-- end #sidebar1 --> <!-- CONTENT --> <div id="mainContent"> ?> I've finally had known that comes from the sidebar.inc.php but what has that to do with anything, I want to use the sidebar, why should the sidebar gets me another record from the database!!!!! PS: I'm putting php tags at the beginning and the end of the page just to highlight the code but they don't exist in the real file pleaaase anyone help!! Link to comment https://forums.phpfreaks.com/topic/134287-solved-please-im-going-nuts-beacause-of-this-bug/ Share on other sites More sharing options...
flyhoney Posted November 26, 2008 Share Posted November 26, 2008 Show us that class you are using for your database stuff. Link to comment https://forums.phpfreaks.com/topic/134287-solved-please-im-going-nuts-beacause-of-this-bug/#findComment-699101 Share on other sites More sharing options...
BloodyMind Posted November 26, 2008 Author Share Posted November 26, 2008 I'm using MySQLi and it's working perfectly in the rest of the classes there you go if that helps: <?php private function getConnection(){ $this->conn = new mysqli($this->dbHost,$this->dbUser,$this->dbPass,$this->dbName); if (!$this->conn) { //throw new DatabaseConnectionErrorException(conn_connect_error()); trigger_error('cannot connect to db'); } return $this->conn; } ?> Link to comment https://forums.phpfreaks.com/topic/134287-solved-please-im-going-nuts-beacause-of-this-bug/#findComment-699103 Share on other sites More sharing options...
flyhoney Posted November 26, 2008 Share Posted November 26, 2008 sidebar.php contains a variable $row, try renaming that. Link to comment https://forums.phpfreaks.com/topic/134287-solved-please-im-going-nuts-beacause-of-this-bug/#findComment-699109 Share on other sites More sharing options...
BloodyMind Posted November 27, 2008 Author Share Posted November 27, 2008 That solved the problem, thanks alot mate, I really appreciate that Link to comment https://forums.phpfreaks.com/topic/134287-solved-please-im-going-nuts-beacause-of-this-bug/#findComment-700268 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.