Each row problem.

Codes here !

Moderators: macek, egami, gesf

Bluesplayer
New php-forum User
New php-forum User
Posts: 4
Joined: Tue Mar 12, 2013 12:47 pm

Each row problem.

Postby Bluesplayer » Wed Mar 27, 2013 2:54 am

I want to add the name of the merchant to the title. I have the code below so far and it works but it goes into some sort of weird loop and keeps repeating itself without working through all the rows (30,000). What I need it to do is cycle through each row once only.

Code: Select all

<?php

$con = mysql_connect('localhost', '', '');
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("", $con);

$sql="SELECT prodName,merchant FROM `affiliSt_products1`";
$result = mysql_query($sql);

while($row = mysql_fetch_array($result))  {
$merchant = $row[merchant];
mysql_query("UPDATE affiliSt_products1 SET prodName = CONCAT(prodName,' By $merchant') WHERE merchant = '$merchant' ") or die(mysql_error());
}

?>


I can never remember how to work while loops, or any loops come to that.

The above is to make the search much more effective. Will make it easy to locate a merchant only product.

User avatar
egami
php-forum GURU
php-forum GURU
Posts: 2196
Joined: Wed Oct 06, 2010 11:19 am
Location: Happy Valley, UT

Re: Each row problem.

Postby egami » Fri Mar 29, 2013 8:07 am

change fetch_array to fetch_assoc

Bluesplayer
New php-forum User
New php-forum User
Posts: 4
Joined: Tue Mar 12, 2013 12:47 pm

Re: Each row problem.

Postby Bluesplayer » Fri Mar 29, 2013 12:09 pm

egami wrote:change fetch_array to fetch_assoc


Thanks

User avatar
egami
php-forum GURU
php-forum GURU
Posts: 2196
Joined: Wed Oct 06, 2010 11:19 am
Location: Happy Valley, UT

Re: Each row problem.

Postby egami » Tue Apr 16, 2013 1:25 pm

Yep


Return to “mySQL & php coding”

Who is online

Users browsing this forum: No registered users and 2 guests

cron