Jump to content

Recommended Posts

hi can someone please help me out i've been trying to solve this problem for a week and cant come up with a solution

 

i have a table `Drinks` with about 10000 entries

 

in that table there's  field names `ID` `Title` `DrinkUri`

 

what i'm trying to do is take the `Title` and put it in `DrinkUri` with a - between the words

 

so example:

 

ID= 1 , Title= Some drink name, DrinkUri would look like Some-drink-name.

 

here is what i've come up with.. it works but it enters the first ID into all of the entries.

 

 

 

the WHERE ID= ?? I need to be incremented somehow using a while loop or something

 

so when i execute the sql.php file it will select ID 1 do its thing the select ID 2 do its thing and so on.....

 

 

 

<?

 

 

require_once( 'inc/header.inc.php' );

require_once( BX_DIRECTORY_PATH_INC . 'design.inc.php' );

require_once( BX_DIRECTORY_PATH_INC . 'admin_design.inc.php' );

require_once( BX_DIRECTORY_PATH_INC . 'languages.inc.php' );

echo "START .....<br /><br />";

 

echo "UPDATING DATABASE .....<br /><br />";

 

    $sTitle = db_value("SELECT `Title` FROM `Drink` WHERE ID = ?? ");

 

 

$sDrinkUri = uriGenerate($sTitle, 'Drink', 'DrinkUri');

 

$res = db_res("UPDATE `Drink` SET  `DrinkUri`='$sDrinkUri' WHERE ID = ?? ");

 

 

 

?>

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/165105-solved-help-with-query/
Share on other sites

If uriGenerate() is literally just replacing spaces with -, you can do this in a single UPDATE query (without a WHERE clause.)

 

What is the code for uriGenerate()?

 

If you are doing more in uriGenerate(), you would just need the first SELECT query to select all the rows (no WHERE clause), then loop through the result set, set $sDrinkUri and execute the UPDATE query for each row.

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.