Answer the question
In order to leave comments, you need to log in
How to make the script itself take the username from the database and process it. After processing, did you move on to the next and so all users from the database?
There is a program that gives data (the number of books on hand) in JSON format
. There is also a user database.
DB dump: file.cbsuzr.ru/lib.zip
DB structure: lib
table1: user
Columns: userid //From here we take the username and insert it into $username
table2: uicheck //If the user meets certain criteria, then we send him to this table .
Columns: userid
book
If you manually write the userid name in $username in the code, then everything works as it should, but how to make it so that when you run the code below, the script itself takes the username from the database (lib\user\userid) and inserts it into ($username),after the number of books on hand is determined and the function "if more than 5 \ then send to the database" works, then the script should go to the next user and check everyone from the table (user\userid) like this. (What is highlighted in bold is what I don’t understand how to implement.)
I know PHP at the level - I can assemble anything, but from pieces of examples ... :)
In general, I came to a dead end ... For I rummaged through many sites, but suitable I did not find a solution in any of the examples.
I would be grateful for help in adding the code, or at least throw a link to an example of the implementation of such a task.
<?php
$db['host']='localhost';
$db['user']='root';
$db['pass']='';
$db['db']='lib';
[email protected]_connect($db['host'],$db['user'],$db['pass']) or die("Ошибка БД");
[email protected]_select_db($db['db']) or die("Ошибка БД");
$userid = "$username";
$data = file_get_contents("http://localhost/json/". $userid);
$json = json_decode($data);
$x = $json->{'book'};
if ($x > 5) {
mysql_query("INSERT INTO uicheck (userid,book) VALUES ('".$userid."','".$x."')");
}
?>
Answer the question
In order to leave comments, you need to log in
<?php $db['host']='localhost'; $db['user']='root'; $db['pass']=''; $db['db']='lib'; [email protected]_connect($db['host'],$db['user'],$db['pass']) or die("DB error"); [email protected]_select_db($db['db']) or die("DB error");
$count=mysql_result(mysql_query("SELECT COUNT(*) FROM `user`"),0);
$q=mysql_query("SELECT * FROM `user` WHERE `userid` LIMIT $count");
while($res=mysql_fetch_assoc($q))
{
$userid=$res['userid'];
$data = file_get_contents(' localhost/json '.$userid);
$json = json_decode($data,true);
$x = $json[book];
if ($x >
5) { $insert=mysql_query("INSERT INTO `uicheck` (`userid`,`book`) VALUES ('$userid','$x')");
}
}
?>
1. Throw away this code
2. Enter data on all users into the database
3. Write a query like "dear base, give me a list of all users who have more than five books"
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question