techwiz101 — 2011-10-31T08:58:28-04:00 — #1
What I want to do is have a script that selects the first row that doesn't have data in that column and then insert something in the columns of that row. Then move on to the next one.
This is my database.
adrian_jc — 2011-10-31T09:41:44-04:00 — #2
You could update all of the empty ones with the same data using,
mysql_query("UPDATE table SET uploads = '232', channelviews = '576', videoviews = '91231' WHERE uploads = ''");
Or, fetch all the empty ones, and loop through them and update them individually.
This way you can set the data for each row, instead of having them all the same.
$fetch_empty = mysql_query("SELECT id FROM table WHERE uploads = '' OR channelviews = ''");
while($empty = mysql_fetch_array($fetch_empty))
// Generate a random number here... use the variable in the query below?
mysql_query("UPDATE table SET uploads = 'xx', channelviews = 'xx', videoviews = 'xx' WHERE id = '" . $empty['id'] . "'");
r937 — 2011-10-31T09:42:31-04:00 — #3
"first" and "move on" are holdover concepts from record-at-a-time procedural thinking
success in database applications comes from switching to set-at-a-time thinking
when you run an sql statement, think of it as operating on all the rows of the table simultaneously
now, what was it you wanted to do again?
techwiz101 — 2011-10-31T09:47:53-04:00 — #4
This is the one I'll try in the morning. (Gotta sleep)
What I want to do is have another bit of code which looks up the values for these columns based on the username given and then moves onto the next row. But then if I run the php file later it will only update the new ones and not all of them.
Also is there a way that I can get one row after another even if it has data in it?
I'll read your responses in the morning.
r937 — 2011-10-31T09:54:59-04:00 — #5
with a cursor, but seriously, read my previous post, this is ~not~ the direction you should be going
techwiz101 — 2011-11-01T03:17:51-04:00 — #6
Well what would you suggest to use, code wise?
I think I might aswell go with what ever you're going to give me as I'm going to have to update it all and not just the empty ones.
guido2004 — 2011-11-01T04:41:02-04:00 — #7
Please explain plain english (not php or mysql code) what you want to do.
Which rows do you want to update, and where do the values come from that you want to put in the table?
r937 — 2011-11-01T07:05:19-04:00 — #8
please give an explanation of what columns you want to update, for which rows, and what values you want those columns to have
techwiz101 — 2011-11-01T08:27:07-04:00 — #9
I want to update all of the columns apart from the ID and username.
I want the other columns to be set by, how do I explain it...
Have a look at this thread I'm in the process of getting my way of retrieving the values for it.
I need this to all go into a file called update.php which I want cron to run if I can.
guido2004 — 2011-11-01T08:39:19-04:00 — #10
Let's suppose you have retrieved your values.
Are they values for one specific row? For several rows? All rows?
What is the connection between those values and the rows in the database table? How do you know which values must be inserted in which row in the database table?
r937 — 2011-11-01T08:40:57-04:00 — #11
when you have something more concrete to offer in this thread, not that one, i'd be happy to help you with your UPDATE statement