Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6235981
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T10:46:13+00:00 2026-05-24T10:46:13+00:00

I have problem with database. I want to add about 10 new rows after

  • 0

I have problem with database. I want to add about 10 new rows after pageload. It should check if there is an article with id (that is actually loading). If its not, add 10 of that id with different tag id.

$sprawdz = "SELECT id_artykulow FROM tag_art WHERE id_artykulow='".$_GET['id']."' " ;
$miasto = mysql_query($sprawdz);   
$a = mysql_num_rows($miasto); 
while ($a<=10){ 
$zm = "SELECT id FROM tag_content ORDER BY RAND() LIMIT 1";
$sw = mysql_query($zm);
while($row3=mysql_fetch_array($sw)){
$zmienna = "INSERT INTO tag_art(id_artykulow, id_tagow) VALUES ('".$_GET['id']."', '".$row3['id']."' ) ";
$cokolwiek = mysql_query($zmienna);
}
$a++; 
}  

There is two tables. One tag_content with id (of the tags), and another tag_art with id_artykulow (= id of the article) and id_tagow (id of the tag taken from tag_content)
Don’t know why, but it doesn’t add 10 rows (it should be for example ten id_artykulow = 10, with different id_tagow). How to fix it?

Thx for help and let me know if u need more informations (like more code etc.)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T10:46:16+00:00Added an answer on May 24, 2026 at 10:46 am

    why do you have 2 while loops?
    cant you just replace

    while ($a<=10){ 
    $zm = "SELECT id FROM tag_content ORDER BY RAND() LIMIT 1";
    

    with

    if ($a<=10){ 
    $zm = "SELECT id FROM tag_content ORDER BY RAND() LIMIT " . (10-$a);
    

    or just let the databse do all the work by:

    $query = "INSERT INTO tag_art(id_artykulow, id_tagow) SELECT '".$_GET['id']."', id  FROM tag_content ORDER BY RAND() LIMIT " . (10-$a);
    

    (and i would also recomendate protection agains sql-injections, mysql_real_escape_string())

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: SQL Server Database query help Hi, I have a problem that I
I have problem with add new row to the table. I use Google Maps,
I am using CakePHP framework with MySQL database and I have problem in saving
I have the following problem in a Database using Access 2007 as front end
i have a problem in inserting the listbox value into mysql database in vb
I have a problem in php code inserting values into database (I use PHPMyAdmin).
i have a problem in inserting the listbox value into mysql database in vb
I currently have a problem attepting to update a record within my database. I
I have a problem using the SSIS. I try to import data from database
This is probably the most classic database problem. I have an E-commerce software solution

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.