Welcome to the GoFuckYourself.com - Adult Webmaster Forum forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Post New Thread Reply

Register GFY Rules Calendar
Go Back   GoFuckYourself.com - Adult Webmaster Forum > >
Discuss what's fucking going on, and which programs are best and worst. One-time "program" announcements from "established" webmasters are allowed.

 
Thread Tools
Old 09-29-2009, 04:26 AM   #1
thunder99
Confirmed User
 
thunder99's Avatar
 
Industry Role:
Join Date: Nov 2003
Location: Budapest
Posts: 503
PHP guys (or gals!) - quick question

I have data in a mysql table in the format:

description title:description text;description title2:description text2;
etc

Is there any way I put this into an array (or something simillar) to print it out and format it nicely?
__________________
yeah, yeah
thunder99 is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 09-29-2009, 04:39 AM   #2
fris
Too lazy to set a custom title
 
fris's Avatar
 
Industry Role:
Join Date: Aug 2002
Posts: 55,241
http://www.php.net/explode
__________________
Since 1999: 69 Adult Industry awards for Best Hosting Company and professional excellence.


WP Stuff
fris is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 09-29-2009, 04:42 AM   #3
StariaDaniel
Confirmed User
 
Join Date: Oct 2007
Location: Netherlands
Posts: 415
first explode the string on every ;, next explode every array element on :

http://de.php.net/manual/en/function.explode.php

e.g.:

$tmp = 'description title:description text;description title2:description text2';
$tmp2 = explode(';',$tmp);

returns:

$tmp2[0] = 'description title:description text';
$tmp2[1] = 'description title2:description text2';

now you could do something like:
$tmp3 = array();
foreach($tmp2 AS $value){
$tmp3[] = explode(':',$value);
}

and you get

$tmp3[0] = array(
0 => 'description title',
1 => 'description text'
);
$tmp3[1] = array(
0 => 'description title2',
1 => 'description text2'
);
StariaDaniel is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 09-29-2009, 04:46 AM   #4
frank7799
Confirmed User
 
frank7799's Avatar
 
Industry Role:
Join Date: Jul 2003
Location: In the middle of nowhere...
Posts: 1,974
You can use a query and put the result into an array. There is an example below. You will need html where the variables are integrated in the "while" loop.


PHP Code:
$query "select description,title from ".MYSQLTABLE." where (site = '$site') $order";
$result mysql_query($query);

    
$number mysql_numrows($result);
    
    
$i 1;
    while (
$i <= $number)
    {
 
      
$row   mysql_fetch_array($result);
      
$title stripslashes($row["title"]);
      
$description stripslashes(nl2br($row["description"]));

      
$i++;
     } 
frank7799 is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 09-29-2009, 05:20 AM   #5
CurrentlySober
Too lazy to wipe my ass
 
CurrentlySober's Avatar
 
Industry Role:
Join Date: Aug 2002
Location: A Public Bathroom
Posts: 38,499
U smell of wee-wee
__________________


👁️ 👍️ 💩
CurrentlySober is online now   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 09-29-2009, 05:34 AM   #6
irbobo
Confirmed User
 
irbobo's Avatar
 
Industry Role:
Join Date: Dec 2005
Posts: 410
PHP Code:
<?
$str = "description title:description text;description title2:description text2;";

function data_to_array($str)
{
    foreach( explode(';',$str) as $value )
        if( !empty($value) && strstr($value, ':') )
            $newarray[] =  array( 'title'=>current(explode(':', $value)), 'description'=>end(explode(':', $value)) );
        
    return $newarray;
}

print_r(data_to_array($str));
?>
output is:

Code:
Array
(
    [0] => Array
        (
            [title] => description title
            [description] => description text
        )

    [1] => Array
        (
            [title] => description title2
            [description] => description text2
        )

)
__________________

Last edited by irbobo; 09-29-2009 at 05:36 AM..
irbobo is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 09-29-2009, 05:40 AM   #7
irbobo
Confirmed User
 
irbobo's Avatar
 
Industry Role:
Join Date: Dec 2005
Posts: 410
in reference to my above post:

Code:
<?
	$mydata = data_to_array($str);
	
	foreach($mydata as $data)
	{
		echo $data['title']."<br />";
		echo $data['description']."<br />";
		echo "<hr />";
	}
?>
__________________
irbobo is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 09-29-2009, 05:42 AM   #8
irbobo
Confirmed User
 
irbobo's Avatar
 
Industry Role:
Join Date: Dec 2005
Posts: 410
another thing if your PHP is set to super strict you may want to return $newarray as @$newarray to avoid tripping a warning if there is no data sent to the function.
__________________
irbobo is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 09-29-2009, 08:06 AM   #9
thunder99
Confirmed User
 
thunder99's Avatar
 
Industry Role:
Join Date: Nov 2003
Location: Budapest
Posts: 503
Thanks fris, StariaDaniel, m4yadult & irbobo. That works!
__________________
yeah, yeah
thunder99 is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 09-29-2009, 08:30 AM   #10
irbobo
Confirmed User
 
irbobo's Avatar
 
Industry Role:
Join Date: Dec 2005
Posts: 410
just procrastinating
__________________
irbobo is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 09-29-2009, 08:56 AM   #11
gornyhuy
Chafed.
 
gornyhuy's Avatar
 
Join Date: May 2002
Location: Face Down in Pussy
Posts: 18,041
Quote:
Originally Posted by irbobo View Post
just procrastinating
Same here. Fuck but I'm unmotivated and over tasked today.
__________________

icq:159548293
gornyhuy is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Post New Thread Reply
Go Back   GoFuckYourself.com - Adult Webmaster Forum > >

Bookmarks



Advertising inquiries - marketing at gfy dot com

Contact Admin - Advertise - GFY Rules - Top

©2000-, AI Media Network Inc



Powered by vBulletin
Copyright © 2000- Jelsoft Enterprises Limited.