Solved

String vs Array

Posted on 2008-06-23
3
247 Views
Last Modified: 2008-07-05
PHP
Question:
I have bunch code that im using array to store the data.
I was think to change array to string.
how can i do that
as show below is one small part of my code.
how can i change it to string that i can get the same output result

  $query = mysql_query(select * from student);
   
    while($row = mysql_fetch_array($query))
       {
       $this->GetCompNumberReturn[$i] = $row['COMPNUMBER'];
        $i++;
                       }
0
Comment
Question by:firekiller15
3 Comments
 
LVL 1

Accepted Solution

by:
binarydesignnz earned 250 total points
ID: 21852528
Is this something like what you want?
<?php
 
 

if($query = mysql_query(select * from student)){

    

    $output = "";

    $seperator = "\n"
 

    while($row = mysql_fetch_array($query)){

        $output .= $row['COMPNUMBER'] .$seperator; 

    }

}  
 

?>

Open in new window

0
 

Author Comment

by:firekiller15
ID: 21852815
the $row['COMPNUMBER'] is assign to $output  as a string?

for example i have 3 record can i out display all the 3 record
say i put code above in function a()
and i make $ouput as object variable
then i create a function called function b()
in function b i do this
echo $this->output can the output display all the 3 record in function b?


 
0
 
LVL 19

Expert Comment

by:BrianGEFF719
ID: 21852839
If you want to save the array as a string so that you can save it, you can serialize it:

 $myarray = array('item'=>'value', 'item2'=>'value');
 $mystring = serialize($myarray);
 echo "Your array looks like this serialized: $mystring<br />";
 $myarray_again = unserialize($mystring);
 echo "If we bring it back to an array, we can print_r: <br />";
 print_r($myarray_again);
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Introduction Many web sites contain image galleries; a common design for these galleries includes a page with a collection of thumbnail images.  You can click on each of the thumbnail images to see the larger version of the image.  This is easily i…
Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
The viewer will learn how to dynamically set the form action using jQuery.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now