PHP - Return Array Of Values From Table 2
SELECT field, (array of values from table 2) FROM $table1 t1 LEFT JOIN $table2 ON t1.id=t2.id
... is something like this possible? (where I return records from t1 in a LEFT JOIN, but also get an array of any of the fields/records from the table 2) Similar Tutorials
Table Issue - Multiple Location Values For User Pushes Values Out Of Row Instead Of Wrapping In Cell
Hey guys, I need your help on this please. I am working on a php web application. I have a form that gets information for Supplier and his traveling details. The values are stored in arrays. I would like to store supplier details in Supplier table and the travelling details in the Travel table. Here is the code with the comments. <?php if (isset($_VARS['submitSuppliers'])) { //error checking starts here $isError = false; if (empty($_VARS['supplierName'])) { $isError = true; $_VARS['supplierRequest']['supplierName']['errorMessage'] = 'You need to provide a Supplier Name.'; } if (empty($_VARS['address'])) { $isError = true; $_VARS['supplierRequest']['address']['errorMessage'] = 'You need to provide an Address.'; } if (empty($_VARS['travel'])) { $isError = true; $_VARS['supplierRequest']['city']['errorMessage'] = 'You need to provide travelling details.'; } #this checks if there is no error and then proceeds to save form values if (!$isError) { #This function adds the details and Returns the autoincremented Supplier ID $SupId = add_suppliers($_VARS); if ($SupId) { #=== Now here I would like to save the travelling details in the Travel table using the generated supplier id # $travId = add_Travel($_VARS); //==== how do I segregate only travel details from the $_VARS array to store in travel table? REDIRECT('/supplier/index.html', array('confirmationMessage' => 'Your details have been saved.')); }else { notify_admin('supplierjoin.php'); } }else { $_VARS['supplierRequest']['errorMessage'] = "There was a problem with the information you provided. Please check the form and try again."; } } ?> Kindly help. Any comment or feedback is always welcome. Thank you I am pulling 5 addresses and I am wanting to store these 5 addresses in columns in a separate table. On the query string I put LIMIT 5. How can I store the results of each of the 5 loops into columns in a separate table? The columns are A1(for name), A2(for address), A3 (for city), A4 (for state), A5 (for zip), A6 (for phone), A7 (for miles), .... then I also have B1-B7, C1-C7, D1-D7, and E1-E7. I am basically wanting to store up to 5 addresses in an array and then update them into a mysql table. Code: [Select] foreach ($zips as $key => $value) { $result = mysql_query("SELECT State FROM extreme WHERE Zip = '$key' AND Type='store' AND `InStore` <> 'NO' LIMIT 5", $db); $num_rows = mysql_num_rows($result); while($myrow = mysql_fetch_array ($result)) { $Dealer=$myrow['Dealer']; $Address=$myrow['Address']; $City=$myrow['City']; $State=$myrow['State']; $Zip=$myrow['Zip']; $Phone=$myrow['Phone']; $Miles = $value; } } I have a stdClass Object array with nested User arrays as a value that I would like to display in a table cell. I am struggling and have exhausted a lot of time. I am hoping to get a shove in the right direction if possible. The image below will show what I am trying to do.
$someArray = json_decode($token_result); foreach ($someArray as $key => $value) { $combined[] = "<tr><td>" . $value->customer . "</td><td>" . $value->city . '</td> <td>' . $value->state . "</td><td>" . $value->zipcode . '</td> <td>' . $value->totalUsers . "</td><td>" . $value->totalActiveUsers . "</td><td>" . $value->totalInActiveUsers . '</td><td> <a href="">' . $value->users . "</a></td></tr>"; } foreach ($combined as $value) { print $value; } Here is what my Array and Objects look like Array ( [0] => stdClass Object ( [customer] => SWSH [city] => Thomasville [state] => GA [zipcode] => 31792 [totalUsers] => 6 [totalActiveUsers] => 6 [totalInActiveUsers] => 0 [users] => Array ( [0] => stdClass Object ( [firstName] => xxx [lastName] => xxx [phoneNumber] => [userName] => cb_igwrth@xxx.com [createdBy] => [isActive] => 1 ) [1] => stdClass Object ( [firstName] => Dan [lastName] => Stewart [phoneNumber] => +11111111111 [userName] => dan.sxx@xxx.ga.gov [createdBy] => kwilliams@xxx.com [isActive] => 1 ) ) ) [1] => stdClass Object ( [customer] => xxxx [city] => Carver [state] => MA [zipcode] => 02330 [totalUsers] => 3 [totalActiveUsers] => 3 [totalInActiveUsers] => 0 [users] => Array ( [0] => stdClass Object ( [firstName] => Leo [lastName] => Furtado [phoneNumber] => 781-000-0000 [userName] => LFurtado@xxx.com [createdBy] => TConger@ccccc.com [isActive] => 1 ) ) ) ) Table is attached
hello, normally when i query mysql, it returns my results line by line. im trying to make a print view now that will put 3 results in a row before going to the next row. any help appreciated. not sure if this is possible but i do not know how to return multiple values and read them where the call was made. Code: [Select] $string = "clause1"; func1($string); // somehow read the response and use the return values seperately. // both $string2 and $string3 Code: [Select] function func1($input) { if ($input == "clause1") { $string2= "value2"; $string3= "value6"; } if ($input == "clause2") { $string2= "value3"; $string3= "value7"; } if ($input == "clause3") { $string2= "value4"; $string3= "value8"; } if ($input == "clause4") { $string2= "value5"; $string3= "value9"; } return ($requesttype, $messagetitle); } Hey all. I'm a noob so bare with me. Just started studying php and have an assignment due. At this phase of the project I have to create a form where a user can register data and I should retrieve that data and store it in my database. Now I have already created the form (student_reg.php) and a separate file with php code (demo.php) My database is name "registration" and I am trying to put this info in the "student" table. It has about 15 fields but for now I am only trying trying to insert the 1 field of data to test if it works. Dont know if that may cause problems? So far my demo.php connects to the database successfully. The problem I am having is the information I submit does not showing in the database field. However, I have an id field in my case a student number field which is set to auto increment so it automatically updates (1,2,3,4) with each new sumbitted info. When I submit the info the id field gets updated each time with a new row ( so i assume some information is somehow going through ) however the info I entered will remain blank in its field. :banghead: Heres my form (student_reg.php) Code: [Select] <div id="apdiv3"> <FORM action = "demo.php" method ="post "> <p>Course name:</p> <INPUT TYPE = "text" name="input"/> <INPUT TYPE = "Submit" VALUE = "Submit"/> </div> </FORM> and heres my php code to retrieve the form info Code: [Select] <?PHP include 'includes/config.php'; //connect to database $link=mysql_connect(DB_HOST, DB_USER, DB_PASSWORD); //error check if (!$link) { die('could not connect: ' . mysql_error()); } $db_selected=mysql_select_db(DB_NAME, $link); // error check if (!$db_selected) { die('can\t use ' . DB_NAME . ': ' . mysql_error()); } // Connected to database // retrieve form data $value=(isset($_POST['input'])); $sql = "INSERT INTO student (sname) VALUES ('$value')"; if (!mysql_query($sql)) { die ('Error: ' . mysql_error()); } mysql_close(); ?> I also recieved a notice "undefined index" or something like that from this part of the code "$value=(isset($_POST['input']));" before I inserted "isset" to the code. I'm not sure if what I did fixed the problem or only hid it, or whether that notice was related to the problem I'm having of not retrieving the info. Haha sorry guys know this is probably childs play for you but I just started out and really need to fix this so I can catch up with this project. Feel free to add tips and comments on other areas. Thanks :mrgreen: So I have an existing picklist that i am trying to tweak - I am making it into a multiselect and trying to return multiple values
I have been able to accomplish the first part by adding select 'multiple' but when i submit it only returns results for the last value selected.
Here is the code for the form (Left out the picklists that do not need to be multiple select)
<td align="center" valign="top"> <? // base64_encode(base64_encode( 'test1'))?> <br /> <br /> <form id='report_form' action="driverreport_sd.php" method="post" name="report_form"> <!--<div class="criteria_div">--> <table align="center" class="table_border" cellpadding="5" cellspacing="0" width="80%"> <tr> <td align="right" class="first_td"> Status: </td> <td align="left"> <select multiple name='Status' id='Status'> <? $statuslist=$ObjReport->ObjStatus->get_Status_List(); while($status=mysql_fetch_object($statuslist)) { if($status->Status=="Please Select") { ?> <option value="<?=$status->Status?>" <?=($status->Status==$_REQUEST['Status']?"selected=selected":"")?>> <?=$status->Status?></option> <? } else { ?> <option value="<?=$status->Status?>" <?=($status->Status==$_REQUEST['Status']?"selected=selected":"")?>> <?=$status->Status?></option> <? } } ?> </select> </td> </tr> <td align="center" colspan="2"> <input type="hidden" id='sort_by' name='sort_by' value="<?=$_REQUEST['sort_by']?>" /> <input type="hidden" name='search_val' id='search_val' value="<?=$_REQUEST['search_val']?>" /> <input type="hidden" name='search_by' id='search_by' value="<?=$_REQUEST['search_by']?>" /> <input type="hidden" name="report_submited" value='report_submited' /> <button type="submit" id="report_submited" name="" value='submit'>Submit</button> </td> and here is the return request <? if($_REQUEST['report_submited']) { $ReportData=$ObjReport->generate_report($_REQUEST['Status'],$_REQUEST['School'],$_REQUEST['Campaign'],$_REQUEST['State'],$_REQUEST['Stdtype'],$_REQUEST['Primbad'],$_REQUEST['Rep'],$_REQUEST['From_Date'],$_REQUEST['To_Date'],$_REQUEST['sort_by'],$_REQUEST['search_by'],$_REQUEST['search_val']); $currentTotalRow=mysql_num_rows($ReportData); if($currentTotalRow>0) { ?> Any suggestions would be appreciated Thanks! I call a web service and it retuens the values in the following format
$response = $client->submitRequest($requestParams);Which returns stdClass Object ( [return] => stdClass Object ( [result_code] => 0 [result_data] => City[0]=Chicago [message_text] => ) )what I want is just the value for [result_data] => City[0]=Chicagoassigned to a variable Psedo Code $city = [result_data] => City[0]=Chicago;so that $city = Chicago; Hi all, I'm a first time poster here and I would really appreciate some guidance with my latest php challenge! I've spent the entire day googling and reading and to be honest I think I'm really over my head and need the assistance of someone experienced to advise the best way to go! I have a multi dimensional array that looks like (see below); the array is created by CodeIgniter's database library (the rows returned from a select query) but I think this is a generic PHP question as opposed to having anything to do with CI because it related to working with arrays. I'm wondering how I might go about searching the array below for the key problem_id and a value equal to a variable which I would provide. Then, when it finds an array with a the matching key and variable, it outputs the other values in that part of the array too. For example, using the sample data below. How would you recommend that I search the array for all the arrays that have the key problem_id and the value 3 and then have it output the value of the key problem_update_date and the value of the key problem_update_text. Then keep searching to find the next occurrence? Thanks in advance, as above, I've been searching really hard for the answer and believe i'm over my head! Output of print_r($updates); CI_DB_mysql_result Object ( [conn_id] => Resource id #30 [result_id] => Resource id #35 [result_array] => Array ( ) [result_object] => Array ( ) [current_row] => 0 [num_rows] => 5 [row_data] => ) Output of print_r($updates->result_array()); Array ( [0] => Array ( [problem_update_id] => 1 [problem_id] => 3 [problem_update_date] => 2010-10-01 [problem_update_text] => Some details about a paricular issue [problem_update_active] => 1 ) [1] => Array ( [problem_update_id] => 4 [problem_id] => 3 [problem_update_date] => 2010-10-01 [problem_update_text] => Another update about the problem with an ID of 3 [problem_update_active] => 1 ) [2] => Array ( [problem_update_id] => 5 [problem_id] => 4 [problem_update_date] => 2010-10-12 [problem_update_text] => An update about the problem with an ID of four [problem_update_active] => 1 ) [3] => Array ( [problem_update_id] => 6 [problem_id] => 4 [problem_update_date] => 2010-10-12 [problem_update_text] => An update about the problem with an ID of 6 [problem_update_active] => 1 ) [4] => Array ( [problem_update_id] => 7 [problem_id] => 3 [problem_update_date] => 2010-10-12 [problem_update_text] => Some new update about the problem with the ID of 3 [problem_update_active] => 1 ) ) Hi, My company has 240+ locations and as such some users (general managers) cover multiple sites. When I run a query to pull user information, when the user has multiple sites to his or her name, its adds the second / third sites to the next columns, rather than wrapping it inside the same table cell. It also works the opposite way, if a piece of data is missing in the database and is blank, its pull the following columns in. Both cases mess up the table and formatting. I'm extremely new to any kind of programming and maybe this isn't the forum for this question but figured I'd give it a chance since I'm stuck. The HTML/PHP code is below: <table id="datatables-column-search-select-inputs" class="table table-striped" style="width:100%"> <thead> <tr> <th>ID</th> <th>FirstName</th> <th>LastName</th> <th>Username</th> <th>Phone #</th> <th>Location</th> <th>Title</th> <th>Role</th> <th>Actions</th> </tr> </thead> <tbody> <?php //QUERY TO SELECT ALL USERS FROM DATABASE $query = "SELECT * FROM users"; $select_users = mysqli_query($connection,$query);
// SET VARIABLE TO ARRAY FROM QUERY while($row = mysqli_fetch_assoc($select_users)) { $user_id = $row['user_id']; $user_firstname = $row['user_firstname']; $user_lastname = $row['user_lastname']; $username = $row['username']; $user_phone = $row['user_phone']; $user_image = $row['user_image']; $user_title_id = $row['user_title_id']; $user_role_id = $row['user_role_id'];
// POPULATES DATA INTO THE TABLE echo "<tr>"; echo "<td>{$user_id}</td>"; echo "<td>{$user_firstname}</td>"; echo "<td>{$user_lastname}</td>"; echo "<td>{$username}</td>"; echo "<td>{$user_phone}</td>";
//PULL SITE STATUS BASED ON SITE STATUS ID $query = "SELECT * FROM sites WHERE site_manager_id = {$user_id} "; $select_site = mysqli_query($connection, $query); while($row = mysqli_fetch_assoc($select_site)) { $site_name = $row['site_name']; echo "<td>{$site_name}</td>"; } echo "<td>{$user_title_id}</td>"; echo "<td>{$user_role_id}</td>"; echo "<td class='table-action'> <a href='#'><i class='align-middle' data-feather='edit-2'></i></a> <a href='#'><i class='align-middle' data-feather='trash'></i></a> </td>"; //echo "<td><a href='users.php?source=edit_user&p_id={$user_id}'>Edit</a></td>"; echo "</tr>"; } ?>
<tr> <td>ID</td> <td>FirstName</td> <td>LastName</td> <td>Username</td> <td>Phone #</td> <td>Location</td> <td>Title</td> <td>Role</td> <td class="table-action"> <a href="#"><i class="align-middle" data-feather="edit-2"></i></a> <a href="#"><i class="align-middle" data-feather="trash"></i></a> </td> </tr> </tbody> <tfoot> <tr> <th>ID</th> <th>FirstName</th> <th>LastName</th> <th>Username</th> <th>Phone #</th> <th>Location</th> <th>Title</th> <th>Role</th> </tr> </tfoot> </table>
Hi everyone for my end of studies projects I decided to do a little e-commerce problem on the filter .. I use an ajax request at the click of the checkbox this goes to my controller which calls a method of my Model class but the concern is that .. if the array $ _POST ['brands'] has several elements then only the last one is returned to me? I thought I saw one day that if the same variable is in a url then the last value will be returned to me is for security but how can I do ... I have been there for too long .. and finally despair. . Help me please... :') request payload: brands%5B%5D=arai&brands%5B%5D=bell reply :
<- prepare var_dump ()
string (4) "arai" <- bind
var_dump () of my fetchAll () since the last value taken into account is bell then I get two items of the bell brand from my bdd but no arai ... Edited October 24, 2020 by jcb789error hello. im trying to get some results from a db and all i keep getting is the word ARRAY ?? I want to get all the placeholders that relate to a page. so if pageID=1 has place holder 1, place holder 2 and place holder 3 it will return 1, 2, 3 etc... in the db i have id pageID phNumber 1 1 1 2 1 2 3 1 3 etc.. this is the code i have Code: [Select] public function find_placeholders($pageID=0){ $sql = "SELECT phNumber FROM ".self::$table_name." WHERE pages_id=".$pageID.""; $result_array = self::find_by_sql($sql); return $result_array; } and on the page i have.. Code: [Select] <?php echo Placeholders::find_placeholders($pageID); ?> all i get is Quote Array once i solve this problem i will want to use each number in the array to find the content for each. so if i get 1,2,3 i will try and do some thing like. foreach placeholder number echo elements but 1 step at a time thanks for any help rick phpfreaks I am querying a database using pdo but I keep getting an array that returns two results. As you can see from the array below it returns the id and result and then repeats the result . I only want the keys with text to be returned. Any help would be great. Code: [Select] ( [0] => Array ( [Ticket_ID] => 2 [0] => 2 [Customer_id] => 1 [1] => 1 [Business_Name] => [2] => my database method is Code: [Select] private function queryFetchAllPDO($query) { try { $this->dataObj->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $sth = $this->dataObj->prepare($query); $sth->execute(); echo"I am here"; $result = $sth->fetchAll(); print_r($result); // $stmt = $this->dataObj->query($query); // $stmt->setFetchMode(); // $result = $stmt->fetchAll(); } catch (PDOException $e) { $e->getMessage(); } return $result; } and the query method is Code: [Select] private function clieViewHome() { //find user id $sql = "SELECT Customer_id FROM customer WHERE Username='" . $this->user . "'"; $sessAccess = $this->connection->getQueryFetchPDO($sql); foreach ($sessAccess as $value) { $userID = $value; } //place into query $sql = "SELECT * FROM tickets WHERE Customer_id ='" . $userID . "'"; $tableArr = $this->connection->getQueryFetchAllPDO($sql); print_r($tableArr); foreach ($tableArr as $key => $value) { $return .= "<tr>\n"; foreach ($tableArr[$key] as $value2) { $return .="<td>" . $value2 . "</td>\n"; } $return .= "</tr>\n"; } return $return; } Hi,Dear Frnds...........................I Hope U r all fine. I am using php.Here is the problem in the Return array from function. This is the code. Code: [Select] <?php $store = array(); $test = get_my_links(); print_r($store); function get_my_links() { $my_array = array('e','f','g'); foreach($my_array as $key=> $list) { $store[] = $list; } return $store; } ?> Suppose the array is maked dynamically. please help me..THANKS... I need to return a specific key from the object converted to array but it seems that it dosent work Code: [Select] $toarray = (array)$tmp; $name = array_keys($toarray,'name'); print_r($toarray); print:Array ( [id] => 9 [name] => dfd [text] => fdsf [rating] => 0 [totalv] => 0 ) and when i try to return the key Code: [Select] print_r($name); Array ( => rating [1] => totalv ) But I only need the key whit the 'name' value I am trying to write a program that sends out a newsletter but I am lost at returning an array of emails. This is what I have
<?php require("../PHPMailer/class.phpmailer.php"); include 'includes.php'; $mail = new PHPMailer; $subject = $_POST['subject']; $text = $_POST['newsletterBody']; $unsubscribe = "<br /><br /><br /><br />If you would no longer like to receive these emails, please <a href='removeemail.php'>Click Here</a> to unsubscribe."; $mail->IsSMTP(); // Set mailer to use SMTP $mail->Host = 'localhost'; // Specify main and backup server $mail->Port = '465'; $mail->SMTPAuth = true; // Enable SMTP authentication $mail->Username = '****EMAIL ADDRESS****'; // SMTP username $mail->Password = '****EMAIL PASSWORD*****'; $mail->SMTPAuth = true; $mail->SMTPSecure = 'ssl'; // Enable encryption, 'ssl' also accepted $mail->From = '****EMAIL ADDRESS****'; $mail->FromName = '****NAME****'; $mail->AddAddress('****EMAIL ADDRESS****', '****NAME****'); $email = getEmail("", $DBH); foreach ($email as $newEmail) { $addEmail = $newEmail['email_addr']; $mail->AddAddress($addEmail); $DBH = null; } $mail->AddReplyTo('****EMAIL ADDRESS****', '****NAME****'); $mail->WordWrap = 50; // Set word wrap to 50 characters $mail->IsHTML(true); // Set email format to HTML $mail->Subject = $subject; $mail->Body = $text . "<br /><br /><br /> To unsubscribe to this email please <a href='www.raven-consult.com/newsletter_remove.php'>Click Here</a>"; $mail->AltBody = $text; if(!$mail->Send()) { echo 'Message could not be sent.'; echo 'Mailer Error: ' . $mail->ErrorInfo; exit; } echo "Message has been sent <a href='newsletter.php'>Return back</a>"; ?>This is the portion of the includes file that you need to know. function getEmail($inId, $DBH) { if (!empty($inId)) { $blogstmt = $DBH->prepare("SELECT email_addr FROM newsletter_emails WHERE id = :userId"); $blogstmt->bindParam(":userId", $inId); $blogstmt->execute(); $postArray = $blogstmt->fetchAll(PDO::FETCH_ASSOC); } else { $blogstmt = $DBH->prepare("SELECT * FROM newsletter_emails"); $blogstmt->execute(); $postArray = array(); $results = $blogstmt->fetchAll(PDO::FETCH_ASSOC); foreach($results as $row){ $myPost = new nlEmails($row['id'], $row['email_addr'], $DBH); array_push($postArray, $myPost); } } return $postArray; $DBH = null; } class nlEmails { public $id; public $email; function __construct($inId=null, $inEmail=null, $DBH) { if(!empty($inId)) { $this->id = $inId; } if(!empty($inEmail)) { $this->email = $inEmail; } } }When I try and submit the newsletter to be sent out all I get back is this error. "Cannot use object of type nlEmails as array ......" Hello. I'm new to php and need a little help please. I try to build a class that return an Array of all the table in my db. and be able to get all the data by there col name (like username, password....) but all i got is the last record from the db. here is the class: <?php class db{ function getall($table, $search){ $sql = "SELECT ". $search ." FROM " . $table; $result = mysql_query($sql) or die('Error, insert query failed' . mysql_error()); while($row=mysql_fetch_assoc($result)){ $data = $row; } return $data; } and this is in the html page: $data = $db->getall("users", "*"); foreach($data as $row){ echo $row['fullname']; echo "<BR>"; } can anybody help me with that? I hate array... 😞 So I had a block of code inside my photo-gallery.php script that took the path to my photos directory, and went to that directory, and then read all of the photo filenames into an array. Then in my HTML, I iterate through this array to display all of the photos for my gallery. Now I would like to move that code to an included file so multiple scripts can access it and always be working with the same array. It seems to me that I need to encapsulate my code inside a function? Then I could call my getPhotoFilesArray back to my callings cript, and use that array for whatever. I haven't coded PHP in like 4 years and I am struggling to return the entire array back to my caling script. This is what I have so far... function getPhotoFilesArray($photoPath){ $photoFiles = array(); <code to find corresponding files> $photoFiles gets populated in a loop return $photoFiles; }
Then in my calling script, I have... <?php require_once('../../../secure_outside_webroot/config.php'); require_once(WEB_ROOT . 'utilities/functions.php'); getPhotoFilesArray($photoPath); var_dump($photoFiles);
I get some error...
Notice: Undefined variable: phtoFiles in photo-gallery.php line 133 (which is my var_dump).
<br> Would appreciate help getting this to work!
Edited December 6, 2019 by SaranacLake I'm not versed in PHP OOP and I have some code that I need to echo out onto a page. I don't know what the meaning of $ct->something is in this code. Is this an array of some type? How do I echo out the $ct->title onto another page? Use a function call? I just don't know what all of the $ct variables are and how to get to them. Any help is appreciated. Code: [Select] function current_theme_info() { $themes = get_themes(); $current_theme = get_current_theme(); if ( ! isset( $themes[$current_theme] ) ) { delete_option( 'current_theme' ); $current_theme = get_current_theme(); } $ct->name = $current_theme; $ct->title = $themes[$current_theme]['Title']; $ct->version = $themes[$current_theme]['Version']; $ct->parent_theme = $themes[$current_theme]['Parent Theme']; $ct->template_dir = $themes[$current_theme]['Template Dir']; $ct->stylesheet_dir = $themes[$current_theme]['Stylesheet Dir']; $ct->template = $themes[$current_theme]['Template']; $ct->stylesheet = $themes[$current_theme]['Stylesheet']; $ct->screenshot = $themes[$current_theme]['Screenshot']; $ct->description = $themes[$current_theme]['Description']; $ct->author = $themes[$current_theme]['Author']; $ct->tags = $themes[$current_theme]['Tags']; $ct->theme_root = $themes[$current_theme]['Theme Root']; $ct->theme_root_uri = $themes[$current_theme]['Theme Root URI']; return $ct; } Hey guys, So im building a Content Management System for my A2 project in Computing, and i have a dataBase class. Now, i can return one thing, or do things like inserts however im having a problem returning a list of things such as: dataBase.class.php Code: [Select] public static function getNYCPost($table, $limit) { dataBase::_dbConnect(); if($limit == 0) { //debug: echo 'in as 0'; $data = mysql_query("SELECT id, linklabel FROM ".$table." WHERE showing='1' AND id >= 2"); } if($limit == 1) { //debug: echo 'in'; $data = mysql_query("SELECT id, linklabel FROM ". $table ." WHERE showing='1' AND id >= 2 ORDER BY id DESC LIMIT 5"); return $data; } } When i try to do this in the main code: index.php Code: [Select] <?php $list = dataBase::getNYCPost($pages,1); // echo $list; while ($row = mysql_fetch_array($list)) { $pageId = $row["id"]; $linklabel = $row["linklabel"]; $menuDisplay .= '<a href="index.php?pid=' . $pid . '">' . $linklabel . '</a><br />'; } echo $menuDisplay; ?> $list doesnt return anything, the previous method i used in the class was to make a list and an array and put the contents of the query in an array like: Code: [Select] list($list[] = $row); or something i cant quite remember i saw a youtube video tutorial and it worked for them, but it wasnt for me. If anyone knows how i can return various rows from a database it would be appreciated Thanks. |