-
Posts
14,780 -
Joined
-
Last visited
-
Days Won
43
Everything posted by .josh
-
Where's the data in my array? (Reading from an SQL database)
.josh replied to lamajlooc's topic in PHP Coding Help
[code] <?php $query = "SELECT username, first_name, daily_score, agg_score, av_score, winner, times_won, win_circle, date_last_in FROM users WHERE username = '{$_SESSION['username']}'"; $result = mysql_query($query) or die("Error: ". mysql_error(). " with query ". $query); // Do the query, show problems if any while ($row = mysql_fetch_array($result)) { echo "{$row['username']} {$row['first_name']} etc.. "; } ?> [/code] -
sorry to do this but i dont know where to put it
.josh replied to zhahaman2001's topic in PHP Coding Help
this is a js issue. closing this thread. -
Warning: Cannot modify header information - headers already sent by
.josh replied to cjl's topic in PHP Coding Help
you cannot have any html output before modifying headers. you have html output before your cookie setting stuff. -
you are selecting all your fields (the *) for every row that id equals something specific, like id = 3. now, most people make the id field a unique field, as in, only one id per row. is this not how your table is setup? are you expecting more than one row to have the same id? and btw, you should NEVER directly insert a $_GET variable into a query like that. People can inject their own arbitrary sql code into it and do all sorts of nasty stuff to you.
-
this should work for both of your situations: [code] <?php // example query: $sql = "select x_coor, y_coor from coords"; $result = mysql_query($sql) or die(mysql_error()); // make the array while ($list = mysql_fetch_array($result)) { $coords[] = array('x_coor' => $list['x_coor'], 'y_coor' => $list['y_coor']); } // example output: $i = 0; while($coords[$i]){ foreach($coords[$i] as $key => $val) { echo"$key : $val <br>"; } $i++; } // another example output: foreach($coords as $val) { echo "x: {$val['x_coor']} y: {$val['y_coor']} <br>"; } ?> [/code]
-
yes, as mentioned, you need to use [b]=[/b] not [b]is[/b] and you need the quotes around the data. However using a concactonated string is not necessary. simply doing this: [code] $query1 = "select * from rating where ip='$ip' and url='$url'"; [/code] is okay
-
although... if you have the exact same info further down the page, except sorted a different way, wouldn't it be better to make the list titles (name, location, date) links that the user can click on, and when they do, the page reloads, but runs the query with a different sort by in it? that way you would have less stuff taking up your page and less bandwidth being used (for having more stuff being displayed). example: [code] . . $titles = array('name','location','date'); $sortby = (in_array($_GET['sortby'],$titles)) ? $_GET['sortby'] : 'name'; $query = $DB->query("SELECT name, location, date FROM table ORDER BY $sortby DESC LIMIT 10"); . . // use this in your list titles/headers/whatever you call it echo "<a href = '{$_SERVER['PHP_SELF']}?sortby=name'>Name</a>"; . . [/code]
-
[code] foreach ($query['location'] as $val) { $sortloc[] = $val; } sort($sortloc); [/code]
-
obviously it is a joke article. I mean come on, even if the first part were real, by the time you get to this part: "the school has reconfigured its internet WatchDog software to block access to all internet sites mentioning PHP." One would think that the person in charge of implementing it would explain how retarded they are being.
-
okay then are you sure that your table and field names are currect? change your code to this (add the '..or die(mysql_error()) to the end of your query): [code] <?php // Open database connection include 'dbdata.php'; // Check the number of tickets already sold $result = mysql_query("SELECT id FROM tickets WHERE id = '100'") or die(mysql_error()); $blah = mysql_fetch_assoc($result); // Determine which table to send the data to and include the script if ($blah) { include('tickets_waiting.php'); } else { include('tickets_success.php'); } ?> [/code]
-
then you probably aren't actually connecting to your database. i see this: include 'dbdata.php'; now what's in it? you sure the connect info is right? you sure that dbdata.php actually connects to the db with that info?
-
$result is a result source. you actually have to pull the data out of it, using a variety of available functions. for instance: [code] <?php // Open database connection include 'dbdata.php'; // Check the number of tickets already sold $result = mysql_query("SELECT id FROM tickets WHERE id = '100'"); $blah = mysql_fetch_assoc($result); // Determine which table to send the data to and include the script if ($blah[0] == '100') { include('tickets_waiting.php'); } else { include('tickets_success.php'); } ?> [/code] although, you are kind of doing double work here. Your query is already fetching a result that equals 100. If there is a result, then obviously id = 100, so there's no reason to check it again in php. [code] <?php // Open database connection include 'dbdata.php'; // Check the number of tickets already sold $result = mysql_query("SELECT id FROM tickets WHERE id = '100'"); $blah = mysql_fetch_assoc($result); // Determine which table to send the data to and include the script if ($blah) { include('tickets_waiting.php'); } else { include('tickets_success.php'); } ?> [/code]
-
such a messy piece of code... [code] $DefBody = '[Some irrelevant code/]<tr><td>Halo Moons</td><td>'.$PresetDefHaloMoonFig.'</td><td>'.$DefHaloMoonFig2.'</td></tr> </table>';if($DefHaloMoonFig2=='0'){$DefBody.=' The Attacker has won the battle!'; } else {$DefBody.=' The Defender has won the battle!';} [/code]
-
how about running a test? [code] <?php function timer() { list($usec, $sec) = explode(" ", microtime()); return ((float)$usec + (float)$sec); } $t1 = timer(); // do method 1 $t2 = timer(); // do method 2 $t3 = timer(); $total1 = $t2-$t1; $total2 = $t3-$t2; echo "Method 1 : $total1 <br />"; echo "Method 2 : $total2 <br />"; ?> [/code] edit: I stoled this code snippet from barand's poll. not that i couldn't have done it myself, but i'm lazy such and all. just giving credit where credit is due ;D
-
trying to use mysql_fetch_array but diffrant way Help :-)!!
.josh replied to Monshery's topic in PHP Coding Help
backticks are not necessary unless you are using mysql reserved words..and you shouldn't be using reserved words as table/field names in the first place. -
[url=http://www.phpfreaks.com/tutorials/142/0.php]Inserting and Displaying Information From a Database[/url] same concept, except for that you would split the code up. In your admin.php you would have the form. On your mainpage.php you would have the select query and display.
-
oh great. in a week or 2 are going to list this on your resume as something you're expert in too?
-
Just to be sure it wasn't some permission thing, I looked at the permissions and even made a test account. I was able to make a post there.
-
Problem Viewing Disucsion Threads
.josh replied to Link1337's topic in PHPFreaks.com Website Feedback
problem is still not fixed. let's try not to make several threads about the same problem.. go here: http://www.phpfreaks.com/forums/index.php/topic,108414.0.html thread closed. -
[code] <?php // 1. connect to a db $conn = mysql_connect('localhost','username','password') or die(mysql_error()); $db = mysql_select_db('dbname',$conn) or die(mysql_error()); // 2. select info $id = $user->uid; $sql = "select PID from tableb where UID=$id"; $result = mysql_query($sql, $conn) or die(mysql_error()); // 3. print yes or no $yesorno = mysql_fetch_assoc($result); switch ($yesorno[0]) { case 1 : echo "yes"; break; case 2 : echo "no"; break; default : echo "1 or 2 not found..some kind of error"; } ?> [/code]
-
yeah i've always just drawn little icons myself. Maybe those linkies will save me some time in the future.
-
see my previous post i updated it.
-
Listing data from a table based on selected value
.josh replied to stewart715's topic in PHP Coding Help
[code] <?php $link = mysql_connect("localhost","thepdcom_popnew","PASSWORD"); mysql_select_db("thepdcom_popnew",$link); $query = mysql_query("SELECT buddy FROM buddylist WHERE uid = '7' and received = '1'") or die(mysql_error()); mysql_query($query); $result = mysql_num_rows($query); if ($result > 0) { while ($list = mysql_fetch_array($query)) { echo "{$list['buddy']} <br>"; } } ?> [/code] -
first of all, did you make a new object variable for your class? 2nd of all, you have to actually return $priv inside your function. example: [code] <?php class blah { function check_priv() { if (isset($_SESSION['user']) && isset($_SESSION['pass'])) { $user = $_SESSION['user']; $pass = $_SESSION['pass']; $query = "SELECT priv FROM users WHERE user='$user' AND pass='$pass'"; $priv = mysql_query($query) or die ("Error in query: $query. ".mysql_error()); return $priv; } // end if } // end function check_priv } // end class blah $blarg = new blah; $result = $blarg->check_priv(); if ($result) { // do something with result } else { // user not authorized } ?> [/code] that's just based off your current code tho. you should probably put pretty much all of that inside your class in the first place.