the wierd code

C++, C#, Java, PHP, ect...
Post Reply
User avatar
VZdemon
Posts: 93
Joined: Thu Nov 25, 2010 1:55 pm

the wierd code

Post by VZdemon »

i tried to store and array in a value in mysql, so i inserted the array in a text value like this '1,2,3,...' and i did not successied in getting it from the database and useing it in an array. so after days of frustration i think* i finally successeded in doing that but when ever i test the code, it crashes my browser.i think i might have made an infinit loop or something like that but i really don't know.

so if any1 could tell me where i went wrong and fix the destructive code it would be awsome.
THE CODE:

Code: Select all

<html>
      <head>
      <link rel='stylesheet' rel='text\css' href='forum/fstyle.css'>
      </head>
      <body link="#990000" vlink="#CC0000">
      <table BACKGROUND="images/pnl.png">
      <center><h1> Profile </h1></center><div id='holder'>
           <div id='profile'>
              <?php
              include "connect.php";
      
              $id = $_GET['user_id'];
              $selid = $id - 5;
              $sid = $id + 2;
              $get = "SELECT * FROM users WHERE id='$selid'";
              $query = mysql_query($get)or die(mysql_error());
              $array = mysql_fetch_array($query)or die(mysql_error());

              $friends = $array['friends'];
              $name = $array['name'];
              $image = $array['picid'];
              $posts = $array['posts'];
              $date = $array['date'];
              $title = $array['title'];
              $rank = $array['rank'];
              $size = 500;
              $hide = md5(rand(9999999,0));
              $fary = array($friends);
              $frnds = implode("<br/>",$fary);
              

              echo "<br/><img class='floatright' src='$image' alt='' width='$size' height='$size'>";
              echo "<big>Name: $name</big><a href='add_freind.php?user_id=$sid'> add as a friend</a></big><br/>";
              echo "<big>Posts: $posts</big><br/>";
              echo "<big>Joined at: $date</big><br/>";
              echo "<big>Title: $title</big><br/>";
              echo "<big>Rank: $rank <br/>";
              echo "<big>Friends: </big>";
              for($j=0;$j<$fary;$j++){
                   $f1 = $frnds[2];
                   echo "<br/><a href='user.php?user_id=$sid&$hide'>$f1</a>";
              }
              ?>
          </div></div>
      </table>
      </body>
</html>
it's VZdaemon on xbox live
User avatar
Chris
Posts: 1580
Joined: Wed Sep 30, 2009 7:22 pm

Re: the wierd code

Post by Chris »

Store your array as a serialized PHP array. serialize($array). Then unserialize it when ever you retrieve it, unserialize($string).
Fighting for peace is declaring war on war. If you want peace be peaceful.
User avatar
Callan S.
Posts: 2042
Joined: Sun Jan 24, 2010 5:43 am

Re: the wierd code

Post by Callan S. »

I'm not familair with the implode command? I've used explode and it splits it up, if that's what your trying to do?

Code: Select all

<?php
$dum="yo`hey`aye`me";

$showem=explode("`", $dum);

for ($loop=0;$loop<=count($showem)-1;$loop+=1)
{
echo $showem[$loop]."<br>";
}
?>
Fight Cycle : My latest Browser game WIP
Driftwurld : My Browser Game WIP
Philosopher Gamer : My Blog
User avatar
Jackolantern
Posts: 10891
Joined: Wed Jul 01, 2009 11:00 pm

Re: the wierd code

Post by Jackolantern »

Implode is basically the opposite of explode :)

"Implode" in the PHP Manual
The indelible lord of tl;dr
User avatar
VZdemon
Posts: 93
Joined: Thu Nov 25, 2010 1:55 pm

Re: the wierd code

Post by VZdemon »

thanks guys. :D :D :D
it's VZdaemon on xbox live
Post Reply

Return to “Coding”