Jump to content

nisroc

Members
  • Posts

    40
  • Joined

  • Last visited

Profile Information

  • Gender
    Not Telling

nisroc's Achievements

Member

Member (2/5)

0

Reputation

  1. oh doh, that worked when changed but got another error to work on. thank you
  2. I get this error when I try to scrap data and enter it directly into a Mysql database. The error i get is: Warning: mysql_connect(): No connection could be made because the target machine actively refused it. in D:\xampp\htdocs\scripts\index.php on line 7 Could not connect: No connection could be made because the target machine actively refused it. It works just cannot get it to insert data, I am quite a rookie at php/mysql and my only guess is something to do with my query and table. Can anyone help out here? <?php $dbhost = 'localhost:3036'; $dbuser = 'Name'; $dbpass = 'pass'; $conn = mysql_connect($dbhost, $dbuser, $dbpass); if(! $conn ) { die('Could not connect: ' . mysql_error()); } // Scrap include('simple_html_dom.php'); $html = file_get_html('http://www.lottolore.com/lotto649.html'); $one = $html->find('table[width=480]', 0)->find('td', 0)->plaintext; $two = $html->find('table[width=480]', 0)->find('td', 1)->plaintext; $three = $html->find('table[width=480]', 0)->find('td', 2)->plaintext; $four = $html->find('table[width=480]', 0)->find('td', 3)->plaintext; $five = $html->find('table[width=480]', 0)->find('td', 4)->plaintext; $six = $html->find('table[width=480]', 0)->find('td', 5)->plaintext; $seven = $html->find('table[width=480]', 0)->find('td', 6)->plaintext; $bonus = str_replace('Bonus ', '', $seven); $today = date("Y-m-d"); //Scrap end $sql = 'INSERT INTO draws '. '(Date, Number1, Number2, Number3, Number4, Number5, Number6, Bonus) '. 'VALUES ( $today, $one, $two, $three, $four, $five, $six, $bonus )'; mysql_select_db('lotto'); $retval = mysql_query( $sql, $conn ); if(! $retval ) { die('Could not enter data: ' . mysql_error()); } echo "Entered data successfully\n"; mysql_close($conn); ?>
  3. ah I stop doing that. Thanks again for all your help
  4. No go trying to figure out a error; Fatal error: Call to a member function query() on a non-object in D:\xampp\htdocs\test.php on line 51 Before you gave me this idea i was working on a if else theory but needed to change colno to rownum. I am not sure rownum would have worked the same way with the sql <?php require_once('Connections/Lotto.php'); ?> <?php if (!function_exists("GetSQLValueString")) { function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") { if (PHP_VERSION < 6) { $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue; } $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue); switch ($theType) { case "text": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "long": case "int": $theValue = ($theValue != "") ? intval($theValue) : "NULL"; break; case "double": $theValue = ($theValue != "") ? doubleval($theValue) : "NULL"; break; case "date": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "defined": $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; break; } return $theValue; } } mysql_select_db($database_Lotto, $Lotto); $sql = "SELECT colno, num, COUNT(*) AS CT FROM ( SELECT 1 as colno, Number1 as num FROM Draws UNION ALL SELECT 2 as colno, Number2 as num FROM Draws UNION ALL SELECT 3 as colno, Number3 as num FROM Draws UNION ALL SELECT 4 as colno, Number4 as num FROM Draws UNION ALL SELECT 5 as colno, Number5 as num FROM Draws UNION ALL SELECT 6 as colno, Number6 as num FROM Draws ) as balls GROUP BY colno, num ORDER BY num, colno; "; $Recordset1 = mysql_query($sql, $Lotto) or die(mysql_error()); $row_Recordset1 = mysql_fetch_assoc($Recordset1); $totalRows_Recordset1 = mysql_num_rows($Recordset1); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> </head> <body> <?php echo "<h3>Frequency table</h3> <table border='1' style='border-collapse:collapse'> <tr><th></th><th>Number1</th><th>Number2</th><th>Number3</th><th>Number4</th><th>Number5</th><th>Number6</th></tr>\n"; $res = $database_Lotto->query($sql); $currNum = 0; while (list($col,$num,$ct) = $res->fetch_row()) { if ($num != $currNum) { if ($currNum) { echo "<tr><th>$currNum</th><td>" . join('</td><td>',$freqs) . "</td></tr>\n"; } $freqs = array_fill_keys(range(1,6),0); $currNum = $num; } $freqs[$col] = $ct; } echo "<tr><th>$currNum</th><td>" . join('</td><td>',$freqs) . "</td></tr>\n"; echo "</table>\n" ?> </body> </html> <?php mysql_free_result($Recordset1); ?>
  5. This now works but with a problem of the table. everything is listed in 2 columns and i would like to list it as <table> <tr> <td>Number1</td><td>#</td> <td>Number2</td><td>#</td> <td>Number3</td><td>#</td> <td>Number4</td><td>#</td> <td>Number5</td><td>#</td> <td>Number6</td><td>#</td> </tr> </table> this is my current table code <table border="0"> <tr> <td>1st number</td> <td>#</td> </tr> <?php do { ?> <tr> <td><?php echo $row_TopNumbers['num']; ?></td> <td><?php echo $row_TopNumbers['CT']; ?></td> </tr> <?php } while ($row_TopNumbers = mysql_fetch_assoc($TopNumbers)); ?> </table>
  6. SELECT colno, num, COUNT(*) AS CT FROM ( SELECT 1 as colno, Number1 as num FROM Draws UNION ALL SELECT 2 as colno, Number2 as num FROM Draws UNION ALL SELECT 3 as colno, Number3 as num FROM Draws UNION ALL SELECT 4 as colno, Number4 as num FROM Draws UNION ALL SELECT 5 as colno, Number5 as num FROM Draws UNION ALL SELECT 6 as colno, Number6 as num FROM Draws ) as balls GROUP BY colno, num ORDER BY colno, CT DESC"; error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '"' at line 17 nvm dumb and blind i got it
  7. I spent time trying to get it to work ... both example however nothing so I will try explain myself a little better. I am trying to learn PhP/MySQL by creating a lotto script that shows the most numbers drawn currently in each column. The lotto is drawn with 7 numbers one being a bonus number (do not need for this query). My table is populated with columns ID, Date, Number1 to Number6 and Bonus. My idea is to take Number1 col and find out the most called numbers from top to bottom in it and list them in a table which i have accomplished. However I got stuck when i wanted to do the same thing for Number2 to Number 6 (including Number1) all in one query. with what i have before i added anything else the results came out like this for column Number1 1st number # 1 371 2 330 4 295 3 290 5 226 ... 38 1 i just wish to do the same thing with number1 though number6 and add them to one HTML table. PS thank for the ideas... playing with them taught me more about things i did not understand correctly
  8. I think he means the difference between a Cart and a CMS. if so a cart can be just a script which can be added to a website but the CMS (e-com) could have cart built into it. the CMS system will be easier to deal with in the long run but if you already have a website it might be easier go with just a cart script.
  9. $query_TopNumbers = "SELECT Number1, COUNT(Number1) AS CT FROM Draws GROUP BY Number1 ORDER BY COUNT(Number1) DESC"; I am curious if it is possible to set up "Number1" in the query to be dynamic. i need to count off the columns and the count repeating values which the query is doing. I have 6 columns, Number1, Number2, Number3, Number4, Number5, Number6. Is it possible to make a query such as "SELECT Number . $colNumber, COUNT(Number . $colNumber) AS CT FROM Draws GROUP BY Number . $colNumber ORDER BY COUNT(Number . $colNumber) DESC"; and just loop it? or is there an easier way. I need the results in a table.
  10. \ Thank you and sorry for posting in wrong section
  11. Still trying to get started with php/mysql. My new problem is i wish to count the number of rows in my table so that i can preform a loop when counting multiple column entries. example i have the number 23 listed in 6 different columns and i wish to find out how many times 23 is listed. So i am trying to get a row count which is 3096 and then create a script. problem is the script below i count the rows using SELECT COUNT(*) but the return comes out as the quote below the script. I am obviouly doing something wrong but cannot seems to find a different way to get just 3096 as a return. any help on this... please and thanks. $con = mysql_connect($hostname, $username, $password, $database) or die("Unable to connect to MySQL"); mysql_select_db($database); $result = mysql_query("SELECT COUNT(*) FROM Draws"); $row = mysql_fetch_assoc($result); echo '<pre>'.print_r($row,true).'</pre>'
  12. nisroc

    mySQL date

    I found an example on the internet which seemed to work Ch0cu3r. <?php echo date('F d, Y', strtotime($row_draws['Date'])); ?> I am unsure if this is correct but it does not throw an error, is there anything wrong with using this?
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.