Jump to content

Barand

Moderators
  • Posts

    24,563
  • Joined

  • Last visited

  • Days Won

    822

Everything posted by Barand

  1. Have you tried loading an image of data into a database so you can test a query. It doesn't work too well
  2. Can you provide a dump of the three relevant tables?
  3. You have moved the mysqli_close() back outside the else{..} block after I put it inside for you. If the connection fails then now you will get an error that $con is not a mysqli resource again. I cannot see anything obvious, other you are not checking if the query ran OK, but I cannot test it as I cannot see any of your data or the values of your variables. Any debugging, therefore, will have to be done by you.
  4. Found some misplaced {}s Try function top10news($s, $t, $u, $w) { session_start(); $con = mysqli_connect("**********", "*************", "***************", "************"); if (mysqli_connect_errno($con)) { echo "<p class='sect'>Could not connect to DB</p>"; } else { $q = "SELECT DISTINCT newsitem.niid,newstitle,newssnippet,sitename,newsimage FROM newsitem,newsbusiness INNER JOIN newsbusiness ON newsitem.niid=newsbusiness.niid LEFT JOIN newsimage ON newsitem.niid=newsimage.niid WHERE newsitem.niid=newsbusiness.niid AND newsstatus='enabled' "; if ($u != "Any") { $q = $q . "AND sitename='$u' "; } if ($s =! "Any") { $parts = explode('-', $s); $y = $parts[0]; $m = $parts[1]; $q = $q . "AND YEAR(newsdate) = $y AND MONTH(newsdate) = $m "; } $q = $q . "ORDER BY newsdate DESC LIMIT 0,10"; $result = mysqli_query($con, $q); while ($tnrow = mysqli_fetch_array($result)) { echo " <div class='newssummary'>"; if ("" . $tnrow ['newsimage'] . "" == "none") { echo "<p class = 'newsmore' > < a href = 'newsitem.php?i=" . $tnrow['niid'] . "' > Read More</a > </p>"; } else if ($tnrow ['imageposition'] == 'Centre') { echo "<p class='newsmore'> <a href='newsitem3.php?i=" . $tnrow['niid'] . "'>Read More</a></p>"; } else if ($tnrow ['imageposition'] == 'Right') { echo "<p class='newsmore'> <a href='newsitem2.php?i=" . $tnrow['niid'] . "'>Read More</a></p>"; } else if ($tnrow ['imageposition'] == 'Left') { echo "<p class='newsmore'> <a href='newsitem.php?i=" . $tnrow['niid'] . "'>Read More</a></p>"; } echo "<div class='newspic'><img src='http://www.nortech.org.uk/news/" . $tnrow['newsimage'] . "' alt='" . $tnrow['newstitle'] . "' /></div>"; echo " <p><strong>" . $tnrow['newstitle'] . "</strong></p> <p class='news'>" . $tnrow['newssnippet'] . "</p> </div> <div class='padder1'></div> <div class='rtgreengp'></div> "; } mysqli_close($con); } }
  5. I'm looking at your code. Meanwhile, change your password now that you've published it!
  6. Check out default arguments in the manual http://www.php.net/manual/en/functions.arguments.php#functions.arguments.default
  7. So many errors! Your query to get the image position had syntax errors. I have incorporated it as a join in your main query. You should not run queries inside loops. I think this may be closer to what you want function top10news($s, $t, $u, $w) { $con = mysqli_connect("connection to database"); if (mysqli_connect_errno($con)) { echo "<p class='sect'>Could not connect to DB</p>"; } else { $q = "SELECT DISTINCT newsitem.niid,newstitle,newssnippet,sitename,newsimage,imageposition FROM newsitem INNER JOIN newsbusiness ON newsitem.niid=newsbusiness.niid LEFT JOIN newsimage ON newsitem.niid=newsimage.niid WHERE newsstatus='enabled' "; if ("$u" == "Any") { } else { $q = $q . "AND sitename='$u' "; } if ("$s" == "Any") { } else { $parts = explode('-', $s); $y = $parts[0]; $m = $parts[1]; $q = $q . "AND YEAR(newsdate) = $y AND MONTH(newsdate) = $m "; } $q = $q . "ORDER BY newsdate DESC LIMIT 0,10"; $result = mysqli_query($con, $q); while ($tnrow = mysqli_fetch_array($result)) { echo " <div class='newssummary'>"; if ("" . $tnrow['newsimage'] . "" == "none") { echo "<p class = 'newsmore' > < a href = 'newsitem.php?i=" . $tnrow['niid'] . "' > Read More</a > </p>"; }else { if ($tnrow['imageposition'] == 'Centre') { echo "<p class='newsmore'> <a href='newsitem3.php?i=" . $tnrow['niid'] . "'>Read More</a></p>"; }else if ($tnrow['imageposition'] == 'Right') { echo "<p class='newsmore'> <a href='newsitem2.php?i=" . $tnrow['niid'] . "'>Read More</a></p>"; }else if ($tnrow['imageposition'] == 'Left') { echo "<p class='newsmore'> <a href='newsitem.php?i=" . $tnrow['niid'] . "'>Read More</a></p>"; } echo "<div class='newspic'><img src='http://www.nortech.org.uk/news/" . $tnrow['newsimage'] . "' alt='" . $tnrow['newstitle'] . "' /></div>"; } echo " <p><strong>" . $tnrow['newstitle'] . "</strong></p> <p class='news'>" . $tnrow['newssnippet'] . "</p> </div> <div class='padder1'></div> <div class='rtgreengp'></div> "; } } }
  8. A record cannot have a article number that at is both A and B, but it can be A or B SELECT Godina, SUM(Prodana_koicina) as Total FROM katalog_pribora_povijest WHERE Br_artikla IN ('544 90 90-01', '578 44 65-01') GROUP BY godina
  9. There is no point in putting the values from the array into 108 separate variable (6x18) When using foreach ($array as $key => $value) it loops through the array putting the key into $key (in this case the description ($desc) such as par, frontyardage etc) and the value into $value. In this case the value is an array of the 18 hole values. The indexes of these arrays is numeric from 0 to 17 (ie hole - 1). I used $tee for the hole number. So, if you want the par value for the 12th hole it would be in the variable $teeboxes['Par'][11] The FrontYardage for for 6th hole would be in $teeboxes['FrontYardage'][5]
  10. so you need to trim the lines from the file while($line = trim(fgets($fh)))
  11. You just need a couple of custom sort functions, one for ascending and the other for descending sorts usort($newScore1, 'mysortAsc'); // or // usort($newScore1, 'mysortDesc'); function mysortAsc($a, $b ) { if (in_array($a['score1'], array(0,'DNF'))) return 1; if (in_array($b['score1'], array(0,'DNF'))) return -1; return $a['score1'] - $b['score1']; } function mysortDesc($a, $b ) { if (in_array($a['score1'], array(0,'DNF'))) return 1; if (in_array($b['score1'], array(0,'DNF'))) return -1; return $b['score1'] - $a['score1']; }
  12. $add = "0.00000001"; $have = "0.00000006"; $have += $add; echo number_format($have, ; //--> 0.00000007 printf('%0.8f', $have); //--> 0.00000007
  13. Like this $teeboxes = array ( "Par" => array ("4","5","3","4","3","4","4","5","4","4","5","3","4","3","4","4","5","4"), "BackYardage" => array ("410","525","173","394","133","410","425","590","410","410","525","173","394","133","410","425","590","410"), "MiddleYardage" => array ("410","525","173","394","133","410","425","590","410","410","525","173","394","133","410","425","590","410"), "FrontYardage" => array ("410","525","173","394","133","410","425","590","410","410","525","173","394","133","410","425","590","410"), "ForwardYardage" => array ("410","525","173","394","133","410","425","590","410","410","525","173","394","133","410","425","590","410"), "SeniorYardage" => array ("410","525","173","394","133","410","425","590","410","410","525","173","394","133","410","425","590","410"), ); /********************************************* * Display the data **********************************************/ for ($tee=1; $tee<=18; $tee++) { echo "<strong>Tee : $tee</strong><ul>"; foreach ($teeboxes as $desc => $data) { echo "$desc : {$data[$tee-1]}<br>"; } echo "</ul><br>"; } /* RESULTS Tee : 1 Par : 4 BackYardage : 410 MiddleYardage : 410 FrontYardage : 410 ForwardYardage : 410 SeniorYardage : 410 Tee : 2 Par : 5 BackYardage : 525 MiddleYardage : 525 FrontYardage : 525 ForwardYardage : 525 SeniorYardage : 525 ... etc */ But why not just pull it from your database on the page where you want to display the data?
  14. $howmanydayspassed = floor(($now-$adate)/86400) ;
  15. try $data = "Marja_Roxburgh|abc@abc.com|123-456-7890|N/A|2011-11-17|N/A|N/A|N/A|N/A|N/A|120, Santa_Roxburgh|bmw@abc.com|123-456-7890|N/A|2013-11-17|N/A|N/A|N/A|N/A|N/A|10, Marja_Roxburgh|abc@abc.com|123-456-7890|N/A|2012-11-17|N/A|N/A|N/A|N/A|N/A|300, Saga_Shera|xyz@abc.com|123-456-7890|N/A|2013-11-17|N/A|N/A|N/A|N/A|N/A|0, Marja_Roxburgh|abc@abc.com|123-456-7890|N/A|2013-11-17|N/A|N/A|N/A|N/A|N/A|120"; $array = array_map('trim', explode(',', $data)); $results = array(); foreach ($array as $record) { $recArray = explode('|', $record); $key = $recArray[0]; $qty = $recArray[10]; if (isset($results[$key])) $results[$key] += $qty; else $results[$key] = $qty; } echo '<pre>',print_r($results, true),'</pre>'; /**** RESULTS ******************** Array ( [Marja_Roxburgh] => 540 [Santa_Roxburgh] => 10 [Saga_Shera] => 0 ) **********************************/
  16. imagecopy
  17. I wonder why they introduced DateTime in 5.2 when you can't do anything with it until 5.3 Back to the old-fashioned ways $adate = strtotime('2013-10-20'); $bdate = strtotime('2013-11-01'); $now = mktime(0,0,0); echo '<pre>'; printf("%-15s\t%s\n", 'Date', 'Days elapsed'); while ($adate < $bdate) { printf("%-15s\t%6d\n", date('d M Y', $adate), floor(($now-$adate)/86400) ); $adate = strtotime('+1 days', $adate); } echo '</pre>';
  18. The dropdown name is "taxrate". You also refer to $_POST['id'] but I don't see anything with the name "id" in the form either
  19. This should work with just DateTime objects $adate = new DateTime('2013-10-20'); $bdate = new DateTime('2013-11-01'); $now = new DateTime(); #$period = new DatePeriod($adate, new DateInterval('P1D'), $bdate); echo '<pre>'; printf("%-15s\t%s\n", 'Date', 'Days elapsed'); while ($adate < $bdate) { printf("%-15s\t%6d\n", $adate->format('d M Y'), floor(($now->getTimestamp()-$adate->getTimestamp())/86400)); $adate->modify('+1 days'); } echo '</pre>';
  20. put in some checks $sql = "SELECT $dim FROM $tbl_name WHERE username='$myusername' and password='$mypassword'"; $takevalue=mysql_query($sql); // check for errors in query if (!$takevalue) { echo "$sql<br>" . mysql_error(); } else { // check if any records found if (mysql_num_rows($takevalue)==0) { echo "No matching records<br>"; } else { $array = mysql_fetch_array($takevalue); $mid=$array['MID']; echo $mid.'<br/>'; } }
  21. DatePeriod and DateInterval require PHP >= 5.3 $adate and $bdate are the start and end dates for the DatePeriod loop.
  22. If you search on a column that isn't indexed then every record has to read to find the ones required. As you are using the primary index then you don't have to worry about adding another (for this query). As for how fast - try it. I haven't got a million people_record table on me right now.
  23. Yes.
  24. Where you have something like (several places) <p class='newsmore'> <a href='newsitem.php?i=" . $tnrow['niid'] . "'>Read More</a></p> you need echo "<p class='newsmore'> <a href='newsitem.php?i=" . $tnrow['niid'] . "'>Read More</a></p>"; There is a major problem with your "radio" query. All you have so far is a string containing the query to be executed. You need to run the query using $result = mysqli_query($con, $radio); then fetch the data returned with mysqli_fetch_assoc Trouble is the query as it is will fetch all rows in the table. Are you storing image positions for each item? If so so you need to specify which item you want using a WHERE clause in the query then
  25. Because the id is not numeric it needs to be in quotes select * from people_record where user_id = 'AAAA_00001' Don't use select * unless you really do need all the columns. Specify what you need. The less you retrieve the faster the query. If the id is not the primary key, create a table index on the id column.
×
×
  • 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.