Jump to content

crazysam

New Members
  • Posts

    5
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

crazysam's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. First of all, thank you all so much! This has definitely helped me solve my problem! echo "CREATE TABLE IF NOT EXISTS `favstable` (<br /> `uid` int(11) NOT NULL,<br /> `fav` text NOT NULL<br /> ) ENGINE=MyISAM DEFAULT CHARSET=latin1;<br /> INSERT INTO favestable (uid, fav) VALUES"; while($row = mysql_fetch_array($result)) { $uid = $row['uid']; $favs = explode('|', $row['favs']); $count = count($favs); for($i = 0;$i < $count; $i++) { echo "({$uid}, '{$favs[$i]}')".","."<br />"; } This creates a perfect export file I can simply import, which is good because some of the data moves from localhost to live server. Thank you so, so, so much!
  2. $conn = mysql_connect('localhost', "root", ""); if (!conn){ echo "Unable to connect to MySQL server <br>"; echo "Error" . mysql_errno() . "-" . mysql_error(); exit; } if (!mysql_select_db("test")){ echo "Unable to select database <br>"; exit; } $query = "SELECT uid from favtable"; $result = mysql_query($query) or die(mysql_error()); /*foreach (explode('|', $rows['favs']) as $fav) { echo $row['uid']."<br />"; echo; }*/ $uids = mysql_fetch_array($result); foreach ($uids as $uid){ $query = "SELECT favs from favtable where uid = $uid"; $result = mysql_query($query) or die(mysql_error()); $test1= explode("|",$row['favs']); $test= $test1[1]; echo "$test"; } Let's just say I wanted something really basic, like: (uid, fav) So, for this row: 45 105|81 I would have this output: (45,105) (145,81) Thank you all so much for the help. I'm just having a hard time getting around this.
  3. Thanks so much for the replies! $test1= explode("|",$row['favs]); $test= $test1[1]; echo "$test"; I'm getting blank output for this for some reason.
  4. I mean saving an id with separate rows for each fav id. I can print it out with the id, and then the values broken apart, but I don't know how to structure an SQL query so that item in the array is a separate item in the database. I guess for this, I would want a query that ultimately resulted in something like this:
  5. Thank you for reading my post! I hope that you have a kind heart and decide to assist me. This is a PHP question about a MySQL problem, so I wasn't sure where to go to post this. I'm kind of new to coding, but I'm working on an extension to update an old script. I have a lot of data that is saved in a format that I really don't like. Okay, the old database structure had two columns, one with userid, and the other with an imploded array separated by '|'. On the left, a person's userid number, and on the right, all their favorite stories on the site. id favs 45 105|81 What I want to do is break up these arrays so the table looks like this: id favs 45 105 45 81 My problem is that I'm not sure how to convert the existing data while($row = mysql_fetch_array($result)){ echo $row['uid']."<br />"; print_r (explode("|",$row['favs])); echo "<br />"; } That will print what I want to do, but I don't know how to get that into the database.
×
×
  • 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.