PHP - Problems With A Simple Recordset
Hi,
I'm very new to php and to mysql and I was hoping someone would be kind enough to give me a hand. I'm trying to write a query that returns only one record set.
I'll paste what I have below and the error. I'm sure that I am doing something wrong that is right in front of my face but for the life of me I can't figure it out.
The relevant part of the code is:
require_once ('../mysqli_connect.php');
$movie_id = $_GET['movie_id']; $q = "SELECT * FROM movies WHERE movie_id = $movie_id"; $r = mysqli_query($dbc, $q); echo '<table cols="2" width="1100px" align="center"> <tr> <td align="left" width="240px"><img src="img/boxcovers/small/movie_' . $r['movie_id'] .'_small.jpg"></td> <td></td> </tr> The error I'm getting is: PHP Fatal error: Cannot use object of type mysqli_result as array Help! Similar TutorialsHow to update table records one by one.... I have a table with five records .. I am getting values of month from another function..I would like to fill the values of month into the table.(like jan feb mar april may) respectively in the first row instead of Average. my code is below $insquery = "select * from reporttmp"; $insresult = mysql_query($insquery, $link) or die("Error in sql sytax."); $fel=mysql_num_fields($insresult); $nro=mysql_num_rows($insresult); $i=1; if ($nro > 0) { while ($i < $nro - 1) { $monname = getmonthname($fmonth); $monname = $monname. " ". $fyear; $upquery = ("UPDATE reporttmp SET vdate ='$monname' where mysql_num_row($insresult)=$i"); if(!mysql_query($upquery, $link)) die ("Mysql error ....<p>".mysql_error()); $fmonth = $fmonth + 1; $i = $i + 1; } } [attachment deleted by admin] Hi I have a recordset from a database which outputs a value of '% THOBEKA MFEKA::12110235675?' I need to seach the database based on the number between the :: and ? only. So for example '12110235675'. I have tried this with a sql statement using LIKE but its not working. How can I trim the value from the database so I only get the number out. The amount of characters before the :: can vary. Please can someone give me some advice asap. Rob I don't know if this is the correct Forum to post this under but I'm trying to fill the values of a recordset into an array. Here is what I have but it doens't work so far. function fetch($info) { return mysql_fetch_array($info); } $Proddb = new mysql; $Proddb->connect(); $result = $Proddb->query("SELECT * FROM Colors WHERE id = '1'"); $row = $Proddb->fetch($result) foreach ($row as $value) { echo $value. "<br>"; } $Proddb-> close(); The array is outputting everything twice does anyone know why? Hi again probably a very simple code but not working. I am trying to show a default image "fabric.jpg" if the recordset is empty. If not empty it shows the recordset image at a size of 100X100. This is the code I am using and have probably left something out, any ideas? <img src="<?php if ($row_Recordset3['fabricpicture']==null); echo "<img src='graphics/fabric.jpg'>"; ?>" alt="" name="fabric" width="100" height="100" border="0" align="bottom" id="fabric" title="Selected Bottom Up Blind Fabric" /> I have tried switching the img scr both "" and ' ' but still no joy? I have a table called parties with 3 fields - partyid, partyname, linkid. For any linkid there will be a number of parties somewhere between 2 and 10. I can get a vertical list but have a couple of issues which I can't fix: I want to have a page that displays the list of partynames (alphabetically) horizontally rather than vertically within a piece of text. For example, "The parties linked to you are Party1, Party2, Party3" Also, ideally, I would like the word 'and' before the last Party name so, using the above example, I would get "The parties linked to you are Party1, Party2 and Party3" I have no idea how to do this or if it can be done. Any ideas would be VERY gratefully received. Thanks I have the code below: ---------------------------------------------------------------------- ------------------------------------ <div id="content"> <table width="998" border="0" cellspacing="4" id="stuff"> <?php do { ?> <tr> <td><?php echo $row_Recordset1['name']; ?></td> </tr> <?php } while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)); ?> </table> <div id="spryTable" spry:region="ds1"> <table align="center"> <tr> <th spry:sort="name"> </th> </tr> <tr spry:repeat="ds1" spry:setrow="ds1" spry:hover="hover" spry:select="selected"> <td height="40" align="center">{name}</td> // green line <td height="40" align="center">{name}</td> //orange line </tr> </table> </div> ---------------------------------------------------------------------- -------------------------------- At the moment the green line of code will display the entire record of names, and the orange line displays the entire record again in another column of the table. The problem is, I want half the names to be printed in one column and the other half of names to be displayed in the other column. Can someone show me how to set the php code to do this? I've been trying various things for a while now without success. Thank you. Record set has 2 text fields in the form which is set in a full repeat recordset browse. So, we get a long list of every record in the database. However, I want to be able to click on a single record and make another page appear. I can do this if the display is set as a table without using a text field form -- just the record variable and using a hyperlink. But, I want to use the text field. Wrapping the form only gets me the value of the last record displayed. Help would be appreciated. Two part question: 1) I have a MySql table called "lang_key", which will store all of the common text for a site, which will allow easy site modifications from the "non tech" admin. Now, I am creating a recordest that will pull the information from the table, and create a basic list of variables in php. For example: I connect to the database, and do a wildcard select. I can figure out how to set a basic php variable like the example below: Code: [Select] $query1 = "SELECT * FROM lang_key"; $result = mysql_query($query1); while($row = mysql_fetch_array($result)) { $template = $row['common_text']; } There are three fields in my lang_key table (unique_id, string_id, and common_text') What I want to do is take it a step further from the example and I want $template to be the value of "common_text" Where string_id = "curr_template" I hope this makes sense? I really just want to create my recordset and then populate the website with the recordset info. Part II Do you recommend that I use a lang_key database, or would it be simpler and more efficient to just create a lang page with static variables, and use the php file write option to update the page? Thanks!!! i am currently building a small client to take xml from a post http request and convert it to json i have run into a problem here is the code , it receives everything properly and it can print the xml; but i cant convert it to json or access any elements of the xml, its being really weird Code: [Select] <?php $c = curl_init(); curl_setopt($c, CURLOPT_URL, 'https://api.octranspo1.com/v1.1/GetNextTripsForStop'); curl_setopt($c, CURLOPT_POST, true); curl_setopt($c, CURLOPT_POSTFIELDS, 'appID=00000&apiKey=000000000&stopNo=4316&routeNo=98'); curl_setopt($c, CURLOPT_RETURNTRANSFER, 1); curl_setopt($c, CURLOPT_FOLLOWLOCATION, true ); $response = curl_exec($c); $xml = simplexml_load_string($response) $json = json_encode($xml); echo $xml->asXML(); // this prints the whole xml echo $json; // this just prints {} curl_close( $c ); ?> and here is what it is returning Code: [Select] <?xml version="1.0" encoding="utf-8"?> <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <soap:Body> <GetNextTripsForStopResponse xmlns="http://octranspo.com"> <GetNextTripsForStopResult> <StopNo xmlns="http://tempuri.org/">4316</StopNo> <StopLabel xmlns="http://tempuri.org/">BLOHM 1579</StopLabel> <Error xmlns="http://tempuri.org/" /> <Route xmlns="http://tempuri.org/"> <RouteDirection> <RouteNo>98</RouteNo> <RouteLabel>Tunney's Pasture</RouteLabel> <Direction>Northbound</Direction> <Error /> <RequestProcessingTime>20120406171014</RequestProcessingTime> <Trips> <Trip> <TripDestination>Tunney's Pasture</TripDestination> <TripStartTime>17:24</TripStartTime> <AdjustedScheduleTime>18</AdjustedScheduleTime> <AdjustmentAge>4.18</AdjustmentAge> <LastTripOfSchedule>false</LastTripOfSchedule> <BusType>6E - 60</BusType> <Latitude>45.374141</Latitude> <Longitude>-75.596715</Longitude> <GPSSpeed>59.9</GPSSpeed> </Trip> <Trip> <TripDestination>Tunney's Pasture</TripDestination> <TripStartTime>17:39</TripStartTime> <AdjustedScheduleTime>33</AdjustedScheduleTime> <AdjustmentAge>-1</AdjustmentAge> <LastTripOfSchedule>false</LastTripOfSchedule> <BusType>6E - 60</BusType> <Latitude /><Longitude /> <GPSSpeed /> </Trip> <Trip> <TripDestination>Tunney's Pasture</TripDestination> <TripStartTime>17:59</TripStartTime> <AdjustedScheduleTime>53</AdjustedScheduleTime> <AdjustmentAge>-1</AdjustmentAge> <LastTripOfSchedule>false</LastTripOfSchedule> <BusType>6E - 60</BusType> <Latitude /><Longitude /> <GPSSpeed /></Trip> </Trips> </RouteDirection> </Route> </GetNextTripsForStopResult> </GetNextTripsForStopResponse> </soap:Body> </soap:Envelope> Thanks for the help Hi all, new to PHP and had a syntax question. I have the following code: print "<p>{$row['comment_createdate']}; This prints out a date from my sqlquery as a database datetime. I need to format it to display "Monday June 15, 2010 5:15 pm". I'm not sure how/where to attach a date() function to the record. (If it matters, the line above is inside of a loop going through several records). This really applies to attaching functions to columns within a recordset in general. Many thanks ahead of time. Guys I m trying to make a crawler and the crawler works fine but the problem is that after some random amount of time the crawler crashes with the message "PHP Fatal error: Maximum function nesting level of '100' reached, aborting! in ....." . Please help me out . Is it my code or there is a problem with simple html dom ?? Ok, I submit the form, and when the next page displays, it says recieved with the persons name, but it wont post their email, and it wont ever send the message to the email address......... i've been playing with it all day long and just cannot figure it out, about to rip my hair out... any help would be appreciated. Contact.php page Code: [Select] <?php // Header Include include('includes/header.php'); ?> <!-- BEGIN SITE CONTENT INCLUDES HERE --> <!-- Index page included --> <table border="0" cellpadding="5" cellspacing="0" width="300" align="center"> <tr> <td><font face="verdana" size="2" color=#"000000"><b>Feedback Form</b></font></td> <tr> <td><form name="contact" method="post" action="contact_submit.php"> <font face="verdana" size="1" color="#1b4a1b">Your Name:<br /> <input type="text" name="name" size="25" /> <br /> Email:<br /> <input type="text" name"email" size="25" /> <br /> Comments:</font><br /> <textarea name="comments" rows="5" cols="30"></textarea> <br /><input type="submit" name="submit" value="Send" /> </form></td> </tr> </table> <br /><br /> <!-- / End Index Page --> <!-- / END SITE CONTENT INCLUDES HERE --> <!-- Footer Include --> <?php include('includes/footer.php'); ?> Form Processing Script contact_submit.php Code: [Select] <?php $to = "tonyagmatrix@gmail.com"; $re = "Feedback Form"; $msg = $comments; mail($to,$re,$msg); ?> <html><head><title>Message Recieved</title></head> <body> <h3>Thank you for your feedback <?PHP echo ($name); ?></h3> <br />We value your opinions and any questions will be replyed to your email address: <?php echo ($email); ?> </body></html> Does anyone have any idea wtf is wrong? Hi everyone, I'm trying to select either a class or an id using PHP Simple HTML DOM Parser with absolutely no luck. My example is very simple and seems to comply to the examples given in the manual(http://simplehtmldom.sourceforge.net/manual.htm) but it just wont work, it's driving me up the wall. Here is my example: http://schulnetz.nibis.de/db/schulen/schule.php?schulnr=94468&lschb= I think the HTML is invalid: i cannot parse it. Well i need more examples - probly i have overseen something! If anybody has a working example of Simple-html-dom-parser...i would be happy. The examples on the developersite are not very helpful. your dilbertone Hello, im very green to php and I am having trouble creating a simple log in script. Not sure why this is not working, maybe a mysql_query mistake? I am not receiving any errors but nothing gets updated in the members table and my error message to the user displays. any help is appreciated! here is my php: <?php session_start(); $errorMsg = ''; $email = ''; $pass = ''; if (isset($_POST['email'])) { $email = ($_POST['email']); $pass = ($_POST['password']); $email = stripslashes($email); $pass = stripslashes($pass); $email = strip_tags($email); $pass = strip_tags($pass); if ((!$email) || (!$pass)) { $errorMsg = '<font color="#FF0000">Please fill in both fields</font>'; }else { include 'scripts/connect_db.php'; $email = mysql_real_escape_string ($email); $pass = md5($pass); $sql = mysql_query("SELECT * FROM members WHERE email='$email' AND password='$pass'"); $log_check = mysql_num_rows($sql); if ($log_check > 0) { while($row = mysql_fetch_array($sql)) { $id = $row["id"]; $_SESSION['id']; $email = $row["email"]; $_SESSION['email']; $username = $row["username"]; $_session['username']; mysql_query("UPDATE members SET last_logged=now() WHERE id='$id' LIMIT 1"); }//Close while loop echo "You are logged in"; exit(); } else { $errorMsg = '<font color="#FF0000">Incorrect login data, please try again</font>'; } } } ?> and the form: <?php echo $errorMsg; ?> <form action="log_in.php" method="post"> Email:<br /> <input name="email" type="text" /><br /><br /> Password:<br /> <input name="password" type="password" /><br /><br /> <input name="myBtn" type="submit" value="Log In" /> </form> class curl2{ private $curl_init; private $CURLOPT_URL; public function connect(){ $this->curl_init = curl_init(); } public function debug(){ curl_setopt($this->curl_init, CURLOPT_VERBOSE, TRUE); $fp = fopen("curl2.txt", "w"); curl_setopt($this->curl_init, CURLOPT_STDERR, $fp); curl_setopt($this->curl_init, CURLOPT_RETURNTRANSFER, TRUE); } public function setUrl($url = null){ $this->CURLOPT_URL = $url; curl_setopt($this->curl_init, CURLOPT_URL, $this->CURLOPT_URL); } public function execute(){ $out = curl_exec($this->curl_init); curl_close($this->curl_init); return $out; } } $curl2 = new curl2; $curl2->connect(); $curl2->setUrl("http://www.linuxformat.co.uk"); $curl2->debug(); echo $curl2->execute(); It display a blank page like attachment result1.jpg, but if I move the $fp = fopen("curl2.txt", "w"); curl_setopt($this->curl_init, CURLOPT_STDERR, $fp); curl_setopt($this->curl_init, CURLOPT_RETURNTRANSFER, TRUE); from function debug() and join it with function execute() like this: public function execute(){ $fp = fopen("curl2.txt", "w"); curl_setopt($this->curl_init, CURLOPT_STDERR, $fp); curl_setopt($this->curl_init, CURLOPT_RETURNTRANSFER, TRUE); $out = curl_exec($this->curl_init); curl_close($this->curl_init); return $out; } it return me Linuxformat content ( expected result ) like result2.jpg below is the working code : class curl2{ private $curl_init; private $CURLOPT_URL; public function connect(){ $this->curl_init = curl_init(); } public function debug(){ curl_setopt($this->curl_init, CURLOPT_VERBOSE, TRUE); } public function setUrl($url = null){ $this->CURLOPT_URL = $url; curl_setopt($this->curl_init, CURLOPT_URL, $this->CURLOPT_URL); } public function execute(){ $fp = fopen("curl2.txt", "w"); curl_setopt($this->curl_init, CURLOPT_STDERR, $fp); curl_setopt($this->curl_init, CURLOPT_RETURNTRANSFER, TRUE); $out = curl_exec($this->curl_init); curl_close($this->curl_init); return $out; } } $curl2 = new curl2; $curl2->connect(); $curl2->setUrl("http://www.linuxformat.co.uk"); $curl2->debug(); echo $curl2->execute(); Why I couldn't split "CURLOPT_STDERR, CURLOPT_RETURNTRANSFER" with "curl_exec" Hi can someone pls help, im tryin a tutorial but keep getting errors, this is the first one i get after registering. You Are Registered And Can Now Login Warning: Cannot modify header information - headers already sent by (output started at /home/aretheyh/public_html/nealeweb.com/regcheck.php:43) in /home/aretheyh/public_html/nealeweb.com/regcheck.php on line 46 I'm trying to either update my database if some data matches the if statement, or insert the data in a new row if it doesn't match (if possible). The code will update the database just fine if the data matches, but if not, it won't insert the new data. (When I leave off the if statement it will insert just fine). I fear I'm not using the if...else correctly. Thanks for any help. <?php header("Location: admin_schedule.php"); include("opendatabase.php"); $date=("$_POST[gamedate]"); $week=("$_POST[Week]"); $game=("$_POST[Game]"); $hometeam=("$_POST[team_name_1]"); $awayteam=("$_POST[team_name_2]"); $check = mysql_query("SELECT week_id,game_id FROM schedule"); $row[] = mysql_fetch_array($check); if ($row[week_id]='$week' && $row[game_id]='$game') { mysql_query("UPDATE schedule SET week_id = '$week', game_id = '$game', date = '$date', H_team = '$hometeam', A_team = '$awayteam' WHERE week_id = '$week' AND game_id = '$game'"); } else { mysql_query("INSERT INTO schedule (week_id,game_id,date,H_team,A_team) VALUES('$week','$game','$date','$hometeam','$awayteam')"); } mysql_close($con); the image in my comments box wont show up it gives me an error Code: [Select] Notice: Undefined index: avatar in /home/ecabrera/public_html/profile.php on line 277 and i dont whats wrong with it Code: [Select] // display comments $perpage = 10; $start=0; if(@$_GET['s']) $start = $_GET['s']; $query = mysql_query("SELECT * FROM profile_comments WHERE profile_id='$getid' ORDER BY id DESC LIMIT $start, $perpage"); $numrows = mysql_num_rows($query); if ($numrows > 0){ $next = $start + $perpage; $prev = $start - $perpage; while($row = mysql_fetch_assoc($query)){ $user_id = $row['user_id']; $user_name = $row['user_name']; $comment = nl2br($row['comment']); $date = $row['date']; $avatar = $row['avatar']; echo "<img src='avatars/$avatar'></img><a href='$site/profile?id=$getid'></a> <b> on $date</b><br />"; echo "<div style='margin-left: 10px;'>$comment</div><hr>"; } } else echo "This user has no profile comments.<br />"; // end diplay comment area |