Jump to content

CSkovholm

Members
  • Posts

    12
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

CSkovholm's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Ah, i get it now! Only how would i do the formatting of the array trough the new while? :-\
  2. Hey all. I'm having a little bit of an issue here. I'll start by showing the code: function dbq($sql) { $q = mysql_query($sql); $row = mysql_fetch_array($q); return $row; } $row = dbq("SELECT * FROM admin"); echo $row['username']; Above code obviously displays a function that can be used for single database outputs.. But, i wanna use it for multiple data outputs, using a while with this function. Something like: while($row = dbq("SELECT * FROM admin")) { echo $row['username']; echo "<br />"; } But it returns errors like, either does it display the first row a billion times, or does simply timeout.. How can this be done? Thanks in advance!
  3. Hey experts. I'm using file_get_contents to save a html page into a variable called $djdanmark. Inside that html page i have a line, like this: <font class="class_1">Some Text</font> Now what i want do to by regex, is to retrieve the text inside those two tags. But as far as i am concerned, you can't use the " inside a variable in php.. My code looks like this: $pattern = "/<font class="class_1">(.*?)<\/font>/"; preg_match($pattern, $djdanmark, $matches); echo $matches[1]; Can someone help me with this? Thanks in advance!
  4. Hey experts I'm having a problem during a table layout for a box.. it looks like this: It blocks out my background image for the table i've created with the orange background. In the Td fields it just shows the background color of grey. The table with the orange background has the following stylesheet attacted to it: .orange { background-image:url(img/orange.jpg); padding:5px 5px 5px 5px; width:764px; height:17px; }
  5. Hey there. I'm new to sockets in PHP programming. I've searched the web and found a tutorial, in which there is a coding example. This script is supposed to open a socket between the given IP and port that belongs to a Counter Strike server. I want to send a socket containing some basic input and retrieve it from the server again. However, i get this error.. Warning: socket_bind() [function.socket-bind]: unable to bind address [0]: The requested address is not valid in its context. in C:\wamp\www\cs_script\index.php on line 13 Could not bind to address My code is: <?php // Set time limit to indefinite execution set_time_limit (0); // Set the ip and port we will listen on $address = '178.236.69.70'; $port = 27015; // Create a TCP Stream socket $sock = socket_create(AF_INET, SOCK_STREAM, 0); // Bind the socket to an address/port socket_bind($sock, $address, $port) or die('Could not bind to address'); // Start listening for connections socket_listen($sock); /* Accept incoming requests and handle them as child processes */ $client = socket_accept($sock); // Read the input from the client &#8211; 1024 bytes $input = socket_read($client, 1024); // Strip all white spaces from input $output = ereg_replace("[ \t\n\r]","",$input).chr(0); // Display output back to client socket_write($client, $output); // Close the client (child) socket socket_close($client); // Close the master sockets socket_close($sock); ?> Thanks in advantage.
  6. Thanks! That stored the returned variables into the array.. But how do i plus the variables from the array with eachother, in an implode(); ?
  7. Hey guys, i've got a question. I have a SQl string that goes: "SELECT * FROM products WHERE id IN(20,3,1)" the 3 ids that are shown in the query, represents the product ids for a shopping system. I now have a sql query that retrieves the information about the products. I want to create an array containing the requested values, from the sql query, and then store the array into a variable. Something like this: <?php require "db.php"; //Db connection $sql = "SELECT * FROM products WHERE id IN (20,3,1)"; //Sql $q = mysql_query($sql); //Query $rows = mysql_fetch_assoc($q); //Returned rows $total_price = implode(+, $rows['price']); echo $total_price ?> I know that's not it.. But how is this done? Thanks in advantage!
  8. I don't.. The previous thread was which sql function is used to retrieve multiple ids. This one is about how to use this function together with an array. And i missed the location of my thread, so i've started a new.
  9. Hey guys I have an array with 3 ids. 20, 13 and 1. I now want to create a sql query, that uses the "WHERE id IN ()".. But how do i store the array, into the sql query? Something like "SELECT * FROM blabla WHERE id IN (".$array.")", however, i know you have to loop trough the array to output the values.. But how is this done? Thanks!
  10. Hey guys I was wondering, how it is possible to request multiple ids from a sql query? I have an array, that contains.. lets say, 3 different ids. 20, 12 and 3 for example. I now want to make a sql query, that retrieves the rows from the table from the 3 given ids.. How is this possible? Thanks!
  11. Hey there :-) I'm having some trouble with my script here, as stated above, it's supposed to be a small script that provides you with the oppertunity to go to the next or previous page of a MySql result page. I've set the limit to 1, just to test it. The table i'm retrieving from has 3 rows inserted. The script returns following errors: ChristianPages:(3) [1] Notice: Undefined variable: PHP_SELF in C:\wamp\www\final-fashionlabs\sidescript.php on line 129 2 Notice: Undefined variable: PHP_SELF in C:\wamp\www\final-fashionlabs\sidescript.php on line 129 3 Notice: Undefined variable: PHP_SELF in C:\wamp\www\final-fashionlabs\sidescript.php on line 153 >> Notice: Undefined variable: PHP_SELF in C:\wamp\www\final-fashionlabs\sidescript.php on line 155 Last >> And the script itself: <?php require "include/db.php"; # $sql = "SELECT * FROM brugere"; # $query = mysql_query($sql); # $total_results = mysql_num_rows($query); # $limit = "1"; //limit of archived results per page. # $total_pages = ceil($total_results / $limit); //total number of pages # if (empty($page)) # { # $page = "1"; //default page if none is selected # } # $offset = ($page - 1) * $limit; //starting number for displaying results out of DB # # $query = "SELECT * FROM brugere LIMIT $offset, $limit"; # $result = mysql_query($query); # //This is the start of the normal results... # # while($row=mysql_fetch_array($result)) # { # echo $row['bruger_navn']; # } # # # # // This is the Previous/Next Navigation # echo "<font face=Verdana size=1>"; # echo "Pages:($total_pages) "; // total pages # if ($page != 1) # { # echo "<a href=$PHP_SELF?page=1><< First</a> "; // First Page Link # $prevpage = $page - 1; # echo " <a href=$PHP_SELF?page=$prevpage><<</a> "; // Previous Page Link # } # if ($page == $total_pages) # { # $to = $total_pages; # } # elseif ($page == $total_pages-1) # { # $to = $page+1; # } # elseif ($page == $total_pages-2) # { # $to = $page+2; # } # else # { # $to = $page+3; # } # if ($page == 1 || $page == 2 || $page == 3) # { # $from = 1; # } # else # { # $from = $page-3; # } # # for ($i = $from; $i <= $to; $i++) # # { # if ($i == $total_results) $to=$total_results; # if ($i != $page) # { # echo "<a href=$PHP_SELF?showold=yes&page=$i>$i</a>"; # } # else # { # echo "<b><font face=Verdana size=2>[$i]</font></b>"; # } # if ($i != $total_pages) # echo " "; # } # if ($page != $total_pages) # { # $nextpage = $page + 1; # echo " <a href=$PHP_SELF?page=$nextpage>>></a> "; // Next Page Link # echo " <a href=$PHP_SELF?page=$total_pages>Last >></a>"; // Last Page Link # } # echo "</font>"; # # // This is the end of the Previous/Next Navigation ?>
×
×
  • 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.