Avatar of error2013
error2013 asked on

PHP SQL Add words to field in database table

Hi,

I have a mysql table with the following fields:

id, name, story, rank

I also have 2 authors:

Peter and Paul

I need some code in php what will do the following altogether:

1st:
Select  * from table where rank = 1
Then:
From the output list I need to add the author names into the story fields.

So for example, is the result of the query above is 10 records

Then the name Peter is added to 5 records inside the story field and the name Paul is added to 5 records.

so Peter is added to 50% and Paul is added to 50%

Can anyone help please?
PHPMySQL Server

Avatar of undefined
Last Comment
Ray Paseur

8/22/2022 - Mon
Ray Paseur

Please post the CREATE TABLE statement and the test data you're using.  It will be easy to show you how to do this once we have that starting point.
ASKER
error2013

Example:

table:

  id | field2 | field3
-----------------------------
  1    hello      1
  2    hello2     1

Open in new window


String1 String2

Select * from mytable where field3 = 1

Will return 2 fields...

next...

Insert String1 into 50% of result and String2 into the other 50% of result on field2

Output should be:

  id | field2         |  field3
-----------------------------
  1    String1 hello      1
  2    String2 hello2     1

Open in new window

Ray Paseur

Is this a school assignment?  It seems "theoretical" to the point of "silly."  What is the back-story here that explains why you would do this?
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes
ASKER CERTIFIED SOLUTION
Ray Paseur

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question