PHP - Php Table With Prime Numbers
So I want to create a table with php and html that outputs a 10x10 table with numbers from 0 to 99 and differentiating prime numbers: The problem is that every time it checks prime numbers from 0 to 99 it prints it in every '<tr>'. Ty in advance for the help! It outputs a check of primer numbers from 0 to 99 every tr and i want it to be a single check from 0 to 99 using 10 tr <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> </head> <body> <?php echo "<table>"; for($i=0; $i < 10; $i++){ echo "<tr>"; for($x=0; $x < 10; $x++){ for($i=0;$i<=99;$i++){ $counter = 0; for($j=1;$j<=$i;$j++){ if($i % $j==0){ $counter++; } } if($counter==2){ echo "<td style="background-color: yellow;">".$i."</td>"; }else{ echo "<td style="background-color: blue>".$i."</td>"; } } echo "</tr>"; } } echo "</table>"; ?> </body> </html> Similar Tutorialshi , how to get the prime numbers of the positive integer input and print them? here's what i have at the moment function getPrime($num){ if((int)$num == $num && (int)$num > 0){ for($i = 2; $i < $num; $i++){ for($j = 2; $j < $i; $j++){ if($i % 2 == 1){ echo $i.'<br />'; } } } } } displayPrime(10); the ouput should be Code: [Select] 2,3,5,7 but the output apparently, is Code: [Select] 3 5 5 5 7 7 7 7 7 9 9 9 9 9 9 9 how to solve this? Hey all - What is the appropriate syntax to echo out each character name (vanity_name), and their total number of "ties" "wins" and "losses" Thanks for your help! $q1 = "SELECT Wins, Ties, Losses from game_char WHERE vanity_name='mario'"; $mario_sql = mysql_query($q1); Code: [Select] <?php echo "Mario: " . $mario_sql; ?> I have this code:
<td><form action="" method="post" name="TableData" class="style5" id="TableData"> <table width="800" border="0" bordercolor="#000000" background="Assets/Tablebar.gif"> <!--DWLayoutTable--> <tr> <td width="183" height="20" align="center"><div align="center" class="style11 style1"></div></td> <td width="317" align="center"><div align="center" class="style11"><span class="style2"><?php echo $row_TableData['UserID']; ?></span></div></td> <td width="136" align="center"><div align="center" class="style11"><span class="style2"><?php echo $row_TableData['UserName']; ?></span></div></td> <td width="136" align="center"><div align="center" class="style2 style11"><span class="style11"><span class="style2"><?php echo $row_TableData['Score']; ?></span></span></div></td> <td width="103" align="center" valign="top"><span class="style2 style11"> <?php for($i = 0; $i < $row_TableData['TourWins']; $i++) { echo '<img src="Assets/Medal.gif" />'; } ?> </span></td> </tr> </table> </form> </td> The Table displays fine and it sorts fine win Highest to lowest score, I am wanting to put place numbers Like 1,2,3,4 etc in the first Colom which is in bold, but I don't know what to use. any help would be great. How would I compare 2 random numbers to rows in a table. The table has 4 rows and 2 colums. My table is setup like this: ID hp mp then has just randomly placed numbers from 0 to 5. So far my script looks like this: I have $new_hp=rand(0,5); $new_mp=rand(0,5). Then i query the db by $myquery=doquery("select hp,mp from users"; $myrow=mysql_fetch_array($myquery); once this is done would a while statement like while ($myrow = mysql_fetch_array($myquery) to what each line in the table has? I would then need to compare the random numbers to those entries in the database. Something like if($myrow[hp] == $new_hp && $myrow[mp] == $new_mp) { ? But if the if statement isnt true it needs go back choose another random number and run same again and again until the statement is true and that is where im stuck at so any help would be greatly appreciated Hi, I need to sort variables in groups of up to 15 and put it in an array. For example: $exstract['center_tabOpBody_0'] =5 $exstract['center_tabOpBody_1'] =6 $exstract['center_tabOpBody_2'] =8 $exstract['center_tabOpBody_3'] =1 Should yield: ARRAY( = center_tabOpBody_1,center_tabOpBody_2,center_tabOpBody_3 // <-----15 [1] = center_tabOpBody_0 //<----5 ) Is there some simple function do do the "efficiency" sort? Thanks, Vadim can you have something like.. echo $whatever; this putput 1.2 can you split this number so the first integer will be in $val"(1)" or whatever and the second integer after the "." will be in $val2"(2)" Hey I have a quick question. I am trying to have a part of this PHP script compare two numbers. There is a randomly generated two-digit number named $random and There is another two digit number named $number. I want to make it so the PHP checks to see if $number has any of the same charcters as $random. I don't know how to do this though. I suspect that somehow both numbers need to be broken apart somehow. Any advice would be appreciated. Let me know if I should explain it more clearly Thanks a ton! Hey i'm just woundering how i would echo numbers from a database like 1000000 lets say 1 million how would i go about on echoing it like this 1,000,000 ZhsHero hello again how to get ratio with result max 3 numbers such as 3.00 or 0.11 if im do $mynumbers = 1000 / 400; so reusult to be 1.00 ? and how to put full stop if it is more then 4 numbers result instead of 1000 to have 1.000 This is my current script <?php $iFile = "accounts.txt"; //Put your list lagger's info in this txt file in the same directory as this script. Format is UserID(space)AuthKey $login = file($iFile, FILE_SKIP_EMPTY_LINES); if(!is_file($iFile)) echo "The logins file couldn't be found...".sleep(999999); foreach($login as $line_num => $line) { $login = explode(" ", htmlspecialchars(str_replace(" "," ",$line))); //////////////// ////////////// /////////// ///////// if(stristr($login[1], "\n")) $login[1] = substr($login[1], 0, strlen($login[1])-2); $MobLink = "http://mobsters-fb-apache-dynamic-lb.playdom.com/mob_fb/"; $RefreshStat = file_get_contents($MobLink."refresh_stat?user_id=".$login[1]."&auth_key=".$login[0]); $Mob_Name = explode("<mob_name>", $RefreshStat); $Mob_Name = explode("<", $Mob_Name[1]); $Name = $Mob_Name[0]; $Cash = explode("<cash>", $RefreshStat); $Cash = explode("<", $Cash[1]); $CurrentCash = $Cash[0]; echo $Name."-$".number_format($CurrentCash)." - ".$login[1]."\n"; } sleep(99999); ?> The Script runs through for 100 different accounts, is it possible to add all the Cash values that get echo'd? Hello, Example X = 50 I have been trying to find a way so that I can loop a foreach to insert into a database X and every other number below X unless X already exists. is this possible? -John Hey, I have checkbox and with these I am setting an exam. I want the questions to contain numbers. So for each question a number would be displayed. So far I am Only getting the question and the choices to display. <html> <?php session_start(); include '../Database/connection.php'; $Value22 = mysql_real_escape_string(trim($_POST['myselects'])); $_SESSION['myselect23'] = $Value22; //echo $_SESSION['myselect23']; ?> <body> <form action="Staff_Menu.php" method="post"> <?php include '../Database/previous_q.php'; while($info = mysql_fetch_array( $sql )) { echo "{$info['Que_Question']} <br />\n"; echo "<input type=\"checkbox\" name=\"choice1[]\" value=\"{$info['Que_Choice1']}\" /> "; echo "{$info['Que_Choice1']} <br />\n"; echo "<input type=\"checkbox\" name=\"choice2[]\" value=\"{$info['Que_Choice2']}\" /> "; echo "{$info['Que_Choice2']} <br />\n"; echo "<input type=\"checkbox\" name=\"choice3[]\" value=\"{$info['Que_Choice3']}\" /> "; echo "{$info['Que_Choice3']} <br />\n"; echo "<input type=\"checkbox\" name=\"choice4[]\" value=\"{$info['Que_Choice4']}\" /> "; echo "{$info['Que_Choice4']} <br />\n"; } ?> <input type="submit" value="submit"/> </body> </html> </body> </html> Hello everyone, i am working on a page that displays news topic and would like to have the page numbers at the bottom of the page as links. You know the usual prev (link) then list couple of pages and then next (link). prev - 1 2 3 4 5... next below is the code i have to count my records on my db and display them. but the problem with this is that it displays all of them. page 1 through 50. Code: [Select] $query2 = "SELECT COUNT(title) FROM news"; $result2 = mysql_query($query2); $row = mysql_fetch_row($result2); $total_records=$row[0]; $total_pages = ceil($total_records / 5); for ($i=1; $i<=$total_pages; $i++) { if ($i!=1 and $i !=10) { print "<a href='newsevents.php?page={$i}'> " .$i. " </a>"; } if ($i==$total_pages) { print"<p><a href='newsevents.php?page={$i}'> Last Page </a>"; } if ($i==1) { print "<p class='floatleft'><a href='newsevents.php?page={$i}'> First Page </a>"; } } Can someone help? i have a price i want to add 10%-15% to the base price and that the result will be rounded to 9 in the ones digit place. for example 85 +15%=97.7 $result=99 117+15%=134.55 $result = 139 played with round() and ceil() Working through some beginner stuff and ive copied some code straight out the textbook, word for word yet it produces: Parse error: syntax error, unexpected T_ECHO, expecting ',' or ';' in C:\wamp\www\PHP Work\StringtoNumbers.php on line 11 <html> <head> <title>Strings Into Numbers</title> </head> <body> <h1>Strings Into Numbers</h1> <ul> <?php $n = "0x237a"; echo "<li>".$n."</li>" echo "<li>".($n * 3)."</li>"; $n2 = "34re5"; echo "<li>".($n2 + 2)."</li>"; $n3 = "boo"; echo "<li>".($n3 + 2)."</li>"; ?> </ul> </body> </html> is this a proper way of entering this? Code: [Select] $result = mysql_query("SELECT * FROM jobs WHERE id2 >= '$startdate' AND id2 < '$enddate' ORDER BY id"); Hi Guys
I have a regex conundrum that at first I thought would be very easy but then appears to be quite hard :/
I want to match a string with a regex where the regex can only pass if it contains letters and numbers (nothing else) and it has to contain at least one of each.
I've been trying out lookaheads but just can't get it right.
Any help is appreciated.
Drongo
Hi i got an error. I cant get $new_score and $new_played variables. $name = $_POST["name"]; $score = $_POST["score"]; $result = mysql_query("SELECT * FROM taure_lentele WHERE name='$name'"); $row = mysql_fetch_array($result); if(mysql_num_rows(mysql_query("SELECT name FROM taure_lentele WHERE name='$name'") ) == 1 ) { $old_score = $row['score']; $score + $old_score = $new_score; $old_played = $row['played']; $new_played = $old_played++; mysql_query("DELETE FROM taure_lentele WHERE name='$name'"); mysql_query("insert into `taure_lentele` set `name` = '$name', `score` = '$new_score', `played` = '$new_played"); } Sorry if this has already been solved. Also, I apologize if this is an amateur question... I have a simple form and a script to do some validating of user data, among other tasks. One part of the script is intended to verify a birthday. Code: [Select] $x = $_POST['x']; $x = trim($x); According to the php.net manual, trim() is supposed to remove whitespace before and after a string. My intent by using trim() is to determine if someone tried to skip the birthday field. I have other validation running on the value of $x, but I wanted trim() to remove whitespace. However, the value of x, which in this case is expected to be numeric, such as 12 for a month, ends up being 1. This happens with any 2-digit number that a user might enter into the form field for x. The second number is always removed. Any insight into why trim() removes the second number, 2 in the above example, leaving only a "1" as the value of $x, would be very greatly appreciated. Thanks in advance. I need to be able to add all the numbers together collected from the database with mysql_fectch_array Code: [Select] public function gradeQuery(){ $id = $this->idQuery(); $sql = "SELECT*FROM grades WHERE moviesID = '$id'"; $result = mysql_query($sql); $row = mysql_fetch_array($result); $num_rows = mysql_num_rows($result); } |