Help - Search - Members - Calendar
Full Version: Looping T Hrough A Database Table
Zymic Webmaster Forums > Web Design & Development > Server Side Scripting > PHP
The Seventh Hokage
i have a database table set up in the following way:

owner: person who is using the entry on this line
slot1: an empty slot
slot2: another empty slow

on done to
slot30:


what i am trying to accomplish is...

I'd like to add a word into an empty slot. I would need to loop through the database to first find a value that says "empty" (which is the default)

I'm at a loss where to begin implementing it.

my code:

CODE
$yada="A Sea Slug";
/* here is the blank code i need to fill in */

$putintoDB="INSERT '$yada' INTO `dabadoo` WHERE `name`='Fred'";

any help appreciated
Jacob
Two things firstly.
  1. You need to better explain what you are trying to do here because it is very vague and hard to see exactly what you are trying to do
  2. You should use SQL's update function, not insert.
    SQL
    UPDATE table
    SET column=value, ...
    WHERE column=value
The Seventh Hokage
QUOTE(NaRzY @ Nov 29 2009, 10:36 AM) *
Two things firstly.
  1. You need to better explain what you are trying to do here because it is very vague and hard to see exactly what you are trying to do
  2. You should use SQL's update function, not insert.
    SQL
    UPDATE table
    SET column=value, ...
    WHERE column=value


okay. to explain better think of a backpack.

this backpack has an owner and room for 10 items.

this back pack would represent the table.

the table hold information about belongings.

another example and more accurately.

this table describes the relationship between a magician and all the magical spells he might know.

the question im askin is how do add new spells to his "magical list"
Jacob
Have a button on page, that once clicked, executes the SQL update to find and replace what is required.
The Seventh Hokage
QUOTE(NaRzY @ Dec 2 2009, 09:50 AM) *
Have a button on page, that once clicked, executes the SQL update to find and replace what is required.


that's not the problem. im looking for actual CODE references on how to implment that.

in other words. I'm trying to figure out how i would code finding an emptly slot in the list and adding a value to it in the least amount of work.
Jacob
Something like this might do the trick:
CODE
<?php
//database connection info needed
//some form needed here
//update value
$result = mysql_query("update database set column='value' where column=' ") or die(mysql_error());  
?>

Then you just need to associate that with a form. You should also do a final "select" statement to clean up the end result.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2013 Invision Power Services, Inc.