Jump to content

.josh

Staff Alumni
  • Posts

    14,780
  • Joined

  • Last visited

  • Days Won

    43

Everything posted by .josh

  1. .josh

    sifr

    ::)
  2. [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]
  3. this is a js issue. closing this thread.
  4. you cannot have any html output before modifying headers. you have html output before your cookie setting stuff.
  5. 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.
  6. 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]
  7. 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
  8. 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]
  9. [code] foreach ($query['location'] as $val) {   $sortloc[] = $val; } sort($sortloc); [/code]
  10. 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.
  11. 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]
  12. 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?
  13. $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]
  14. 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]
  15. 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
  16. 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.
  17. [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.
  18. .josh

    sifr

    oh great. in a week or 2 are going to list this on your resume as something you're expert in too?
  19. 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. 
  20. 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.
  21. [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]
  22. yeah i've always just drawn little icons myself. Maybe those linkies will save me some time in the future.
  23. see my previous post i updated it.
  24. [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]
  25. 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.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.