![]() |
![]() |
![]() |
||||
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. |
![]() ![]() |
|
Discuss what's fucking going on, and which programs are best and worst. One-time "program" announcements from "established" webmasters are allowed. |
|
Thread Tools |
![]() |
#1 |
Confirmed User
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 |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#3 |
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' ); |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#4 |
Confirmed User
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:
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#5 |
Too lazy to wipe my ass
Industry Role:
Join Date: Aug 2002
Location: A Public Bathroom
Posts: 38,499
|
U smell of wee-wee
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#6 |
Confirmed User
Industry Role:
Join Date: Dec 2005
Posts: 410
|
PHP Code:
Code:
Array ( [0] => Array ( [title] => description title [description] => description text ) [1] => Array ( [title] => description title2 [description] => description text2 ) )
__________________
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#7 |
Confirmed User
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 />"; } ?>
__________________
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#8 |
Confirmed User
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.
__________________
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#9 |
Confirmed User
Industry Role:
Join Date: Nov 2003
Location: Budapest
Posts: 503
|
Thanks fris, StariaDaniel, m4yadult & irbobo. That works!
__________________
yeah, yeah |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#10 |
Confirmed User
Industry Role:
Join Date: Dec 2005
Posts: 410
|
just procrastinating
__________________
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#11 |
Chafed.
Join Date: May 2002
Location: Face Down in Pussy
Posts: 18,041
|
Same here. Fuck but I'm unmotivated and over tasked today.
|
![]() |
![]() ![]() ![]() ![]() ![]() |