PHP - Problem Displaying Result !
i cannot figure out why my first result is not displaying properly it successfully shows all results but me first
myurl.com/other.php?id=2 now showing any thing kindly help to solved this problem! it seems like problem is in variable $http$ids but dunno how to combine them to get result $Ids always b numeric number <?php ini_set ("display_errors", "1"); error_reporting(E_ALL); $http = "myurl.com/other.php?id=" ; $conn=odbc_connect('greeting','',''); if (!$conn) {exit("Connection Failed: " . $conn);} $sql="SELECT * FROM mytable"; $rs=odbc_exec($conn,$sql); if (!$rs) {exit("Error in SQL");} echo "<table border= 1><tr>"; echo "<th>ID</th>"; echo "<th>Like</th>"; echo "<th>title</th></tr>"; while (odbc_fetch_row($rs)) { $ids=odbc_result($rs,"ID"); $title=odbc_result($rs,"title"); echo "<tr><td>$ids</td>"; echo "<td><fb:like href=\"$http$ids\" layout=\"button_count\" show_faces=\"false\" width=\"100\" font=\"tahoma\" colorscheme=\"dark\"></fb:like> </td>"; echo "<td>$title</td></tr>"; } echo "</table>"; odbc_close($conn); ?> Similar Tutorialsi have it set up so the user picks the year and session and then the database shows all the games in that specific year and session and then displays them with a link to their photo galleria and also shows the record(wins - losses - ties) but the way i have it know its not displaying the first result here is the code Code: [Select] <?php //declares $y as year played and $s as session $y = ' '; $s = ' '; //handles submition of form for picking year and session if (isset($_POST['submit'])) { $data = mysql_real_escape_string($_POST['session']); $exploeded = explode(",", $data); $y = $exploeded[0]; $s = $exploeded[1]; } //Query for the selection menu $squery = "SELECT DISTINCT(Year_Played), Sessions FROM pinkpanther_games"; $sresults = mysql_query($squery) or die("squery failed ($squery) - " . mysql_error()); //checks $y and $s to see if their is a vaule if ($y == ' '){$y = '20112012';} if ($s == ' '){$s = '2';} //Query for getting record and for getting all the appropriate info for displaying the games $query = " SELECT (SELECT COUNT(id) FROM pinkpanther_games WHERE Year_Played = $y AND Sessions = $s AND Win_Loss = 'Tie' ) AS 'Tie', (SELECT COUNT(id) FROM pinkpanther_games WHERE Year_Played = $y AND Sessions = $s AND Win_Loss = 'Win') AS 'Win', (SELECT COUNT(id) FROM pinkpanther_games WHERE Year_Played = $y AND Sessions = $s AND Win_Loss = 'Loss') AS 'Lose', Opponent AS Opponent, Score AS Score, Gallery_no AS Gal, Win_Loss AS Record FROM pinkpanther_games WHERE Year_Played = $y AND Sessions = $s"; $results = mysql_query($query) or die("Query failed ($query) - " . mysql_error()); $row_a = mysql_fetch_assoc($results); //Set record variables $wins = $row_a['Win']; $loss = $row_a['Lose']; $tie = $row_a['Tie']; //creates from and selection menu for year and session echo "<tr><td colspan='2'><form method='post' action=''><select name='session' class='txtbox2'>"; while ($srow = mysql_fetch_assoc($sresults)){ echo "<option value='" . $srow['Year_Played'] . "," . $srow['Sessions'] . "'>" . $srow['Year_Played'] . " Session " . $srow['Sessions'] . "</option>"; } echo "</select><input type='submit' name='submit' value='Go' class='txtbox2' /></form></td></tr>"; //displays record echo "<tr><td colspan='2'>" .$wins . " - " . $loss . " - " . $tie . "</td></tr>"; echo "<tr></tr>"; //displays games and scores in appropriate year and session while ($row = mysql_fetch_assoc($results)){ $opp = $row['Opponent']; $score = $row['Score']; $gal = $row['Gal']; $wlt = $row['Record']; //styles games acording to if win lose or tie if ($wlt == 'Win'){ echo "<tr><td class='win'>"; echo "<a href='galleries.php?g=$gal'" . $gal . " >" . $opp . "</a>"; echo "</td><td class='win'>"; echo $score . ""; echo "</td></tr>"; } if ($wlt == 'Loss'){ echo "<tr><td class='loss'>"; echo "<a href='galleries.php?g=$gal'" . $gal . " >" . $opp . "</a>"; echo "</td><td class='loss'>"; echo $score . ""; echo "</td></tr>"; } if ($wlt == 'Tie'){ echo "<tr><td class='tie'>"; echo "<a href='galleries.php?g=$gal'" . $gal . " >" . $opp . "</a>"; echo "</td><td class='tie'>"; echo $score . ""; echo "</td></tr>"; } } ?> Hi! I want the image of my site to be clickable so that it shows the next image contained in the result set of the sql query. Code: [Select] <?php require_once('includes/connection.inc.php'); $conn = dbConnect(); $sql = 'SELECT filename FROM images ORDER BY image_id DESC LIMIT 1'; $msg = ''; if(!$sql) { echo "Something went wrong with the query. Please try again."; } $result = $conn->query($sql) or die(mysqli_error()); if(mysqli_num_rows($result) == 0) { header('Location: empty_blog.php'); $conn->close(); } else { $row = $result->fetch_row(); $image = $row[0]; } ?> <?php include('header.php'); ?> <div class="content main"> <img id="image" src="images/<?php echo $image; ?>"/> </div> <?php include('includes/footer.inc.php'); ?> All the filenames of the images are contained correctly in the $result variable, all I need to do now is to fetch the next image in the set. How would I go about this? Any help is greatly appreciated! Hi I am building a product search engine using MySql and PHP (Jquery / AJAX). As i am getting the search results i wondered is it possible to count the instances of a category? For example: If i search for "Dell Laptops" i get 400+ results back because it has lots of laptops and accessories. What i am aiming for it to do is while looping through look at the categories and if its the first instanc eof it i want it to begin a count. until it has finished looping and then i can display it. Results: 436 [ Laptops(127) - Accesories (244) - Components(65) ] Im not even sure where to start here so any advice will be helpful Here is the code im using to generate the search: $id = str_replace(" ", "%", "$id"); $q = "SELECT * FROM products WHERE prod_name LIKE '%$id%' order by fee asc LIMIT 20"; Hello! I am busy developing a script that returns all users that have the cell "Available" set to 1 but I am unsure how to do this, I am familiar with basic SQL and I have made this: $sql = "SELECT * FROM `clans` WHERE `available` =1 LIMIT 0 , 30"; if ($result = mysql_query($sql)) { if (mysql_num_rows($result)) { $row = mysql_fetch_assoc($result); echo ($row['name']); but it only displays information from the first row found, and I want it to display all the rows found, how can I do this? Thanks - GreenFanta Hi, I am new to php but not to programming. I created a script on a windows platform which connects to the mysql database and returns the results of a table. A very basic script which I wrote to simply test my connection worked. The script works fine on my windows machine but not on my new mac. On the mac it simply does not display any records at all. I know that the database connection has been established because there is no error but I can not see why the result set is not being displayed on screen, as I said it worked fine on my windows machine. The Mac has mysql (with data) and apache running for php. Please could someone help as I have no idea what to do now? Script below: Code: [Select] $dbhost = 'localhost'; $dbuser = 'root'; $dbpass = 'root'; $conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql'); $dbname = 'test'; mysql_select_db($dbname); mysql_select_db("test", $conn); $result = mysql_query("SELECT * FROM new_table"); while($row = mysql_fetch_array($result)) { echo $row['test1'] . " " . $row['test2'] . " " . $row['test3']; echo "<br />"; } mysql_close($con); This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=330221.0 Hello - Suppose I had a MySQL result set that was something like this: ITEM: COLOR: ball red ball blue book red book green book black If I were to use the code: Code: [Select] do { echo $row_myQuery['item'] . " - " . echo $row_myQuery['color'] . "<br />"; } while ($row_myQuery= mysql_fetch_assoc($myQuery)); Then I end up with this: Code: [Select] ball - red ball - blue book - red book - green book - black MY QUESTION: What I'd like to know is, how could I re-write that php code so that I could get an output like this?: Code: [Select] ball - red, blue book - red, green, black Thanks! Hello all,
Am trying to calculate some data and display the result of the current month in a chart form. i just don't know how to get the current month. this is not working..
<?php include('mysql_connect.php'); $date = 'MONTH(CURRENT_DATE())'; $status = 'paid'; //mysql_select_db("hyprops", $con); $query = mysql_query("SELECT sum(amount) 'amount', department FROM requisition WHERE status = '$status' AND date='$date' "); $category = array(); $category['name'] = 'department'; //$series1 = array(); //$series1['name'] = 'actual'; $series2 = array(); $series2['name'] = 'amount'; //$series3 = array(); //$series3['name'] = 'Highcharts'; while($r = mysql_fetch_array($query)) { $category['data'][] = $r['department']; // $series1['data'][] = $r['actual']; $series2['data'][] = $r['amount']; // $series3['data'][] = $r['highcharts']; } $result = array(); array_push($result,$category); //array_push($result,$series1); array_push($result,$series2); //array_push($result,$series3); print json_encode($result, JSON_NUMERIC_CHECK); mysql_close($con); ?>Please how can i solve this issue? Thanks in advance Hi, Having trouble rounding the output. I would need to be sure the output is not longer than 2 spaces after comma. Any ideas? My code Code: [Select] <script type="text/javascript"> $(document).ready(function() { $("<?php echo "#".$input_end_time; ?>").blur(function(){ var start_time = $("<?php echo "#".$input_start_time; ?>").val(); var end_time = $("<?php echo "#".$input_end_time; ?>").val(); $.getJSON("include/timedifferencecalculation.php?s="+start_time+"&e="+end_time, function(data){ var success = data.success; if (success == 1) { $("<?php echo "#".$input_difference; ?>" ).val(data.hours + " h " + data.minutes + " m "); if (data.hours + data.minutes/60 >= 6){ $("<?php echo "#".$hours_difference; ?>").val(data.hours + data.minutes/60 - 0.5); }else { $("<?php echo "#".$hours_difference; ?>").val(data.hours + data.minutes/60); } }else { $("#message").text("Viga! " + data.reason); } }) }); }); </script> Code: [Select] This is before $("<?php echo "#".$hours_difference; ?>").val(data.hours + data.minutes/60 - 0.5); This is what im trying to get but its not working. $("<?php echo "#".$hours_difference; ?>").val( round(data.hours + data.minutes/60 - 0.5), 2 ); Hello guys I have here my array result Array ( => Array ( => 1 [1] => [2] => 123456789 [3] => [4] => 2012-02-02 [5] => 09:12:21 [6] => Test Array ) ) I would like to view this result into a string so that it will remove the unnecessary array elements like brackets etc. Can some tell me how to handle this properly? The result would be : 1 123456789 2012-02-02 09:12:21 thanks Hi,
Well, I've been wondering if I can get answer to my problem here...
I'd used curl to fetch information from other site and then I need to parse the data to be displayed in our own. However I found something odd...I can't parse it to get what I want...however should I put the result into a html file, n parse the file itself...it's fine.
Basically I just need to find whether a word/phrase is there or not...n I'm using preg_match to do it so far. Since the time it first arises...I'd been googling n saw some posts...something similar to how regex is doing poorly in doing such thing...
However it does work when I just make a php file just to do that regex from the curl-result html file, it just not work on the actual php file which handle the process even if it's from the same curl-result html file. FYI, I'm using codeigniter.
I wonder if it got something to do with codeigniter or something...or is there any other better way to parse a html file from a curl result. In my opinion it's just the same...be it a curl result or just a normal html...so I really can't figure out where it went wrong.
I appreciate if there's anyone who can shed a light on this problem, even a little bit is a great help to me
Thanks in advance,
This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=306966.0 Hey everyone I've been working on converting my old mysql code to to the mysqli version and am running into some trouble. I am pulling posts form phpbb and displaying them in a script. My first script below works just fine. Code: [Select] <?php require("connect.php"); $query="SELECT * FROM phpbb_topics WHERE (forum_id='13' OR forum_id='14') AND topic_status = '0'"; $query2="SELECT * FROM phpbb_topics WHERE (forum_id='15' OR forum_id='16') AND topic_status = '0'"; $result=mysql_query($query); $result2=mysql_query($query2); echo "<table border=0 cellpadding=2>"; echo "<tr><td>Lost</td><td>Found</td></tr>"; while($row=(mysql_fetch_array($result)) || $row2=(mysql_fetch_array($result2))) { $forum_id=mysql_result($result,$k,"forum_id"); $topic_id=mysql_result($result,$k,"topic_id"); $topic_title=mysql_result($result,$k,"topic_title"); $forum_id2=mysql_result($result2,$k,"forum_id"); $topic_id2=mysql_result($result2,$k,"topic_id"); $topic_title2=mysql_result($result2,$k,"topic_title"); echo "<tr><td width='15%'><a href=/sahbb/viewtopic.php?f=$forum_id&t=$topic_id>$topic_title</a></td> <td width='15%'><a href=/sahbb/viewtopic.php?f=$forum_id2&t=$topic_id2>$topic_title2</a></td> </tr>"; $k++; } echo "</table>"; mysql_close($connect); ?> however its not very clean or memory efficient so i have converted it to the following. Code: [Select] <?php require("includes_database/mysqli_connect.php"); $query="SELECT * FROM phpbb_topics WHERE (forum_id='13' OR forum_id='14')"; $query2="SELECT * FROM phpbb_topics WHERE (forum_id='15' OR forum_id='16')"; $result=mysqli_query($dbc, $query); $result2=mysqli_query($dbc, $query2); echo "<table border=1 cellpadding=2>"; echo "<tr><td>Lost</td><td>Found</td></tr>"; while(($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) || ($row2 = mysqli_fetch_array($result2, MYSQLI_ASSOC))) { echo "<tr><td width='15%'><a href=/sahbb/viewtopic.php?f=".$row['forum_id']."&t=".$row['topic_id'].">".$row['topic_title']."</a></td> <td width='15%'><a href=/sahbb/viewtopic.php?f=".$row2['forum_id']."&t=".$row2['topic_id'].">".$row2['topic_title']."</a></td> </tr>"; } echo "</table>"; mysqli_free_result($result); mysqli_free_result($result2); mysqli_close($dbc); ?> I know the error is in my while loop but i cant seem to figure out exactly where. The new code displays all of the first query in the table and then below that it displays the next query insted of displaying them side by side below would be an example of what is happening [table Lost Found Lost, Australian Sheppard Lost German Shepherded / Collie Mix Lost Golden Retriever/Cocker Mix Lost Female Grey Tiger Lost Pitbull Mix Lost 2 Chihuahua Lost Black Lab Lost - German Shepard Mix and Lab Mix Lost - Female German Sheperd Aprox 8 Week Old Kitten Found! 2 Pugs FOUND Found 1 Corgi female/ 1 Shih Tzu male Found Tan and Black Australian Shepard Found Australian Shepard Found Intact Male Pitbull/Lab Mix Any help that any of you could provide would be greatly appreciated! Hi, it's my first post so hello to you and i hope you will be forgiving:) I've made a basic script, which takes a urls from the form(each of them is the new row) and then search each of those urls for an email. The problem is that only the email from the last url is returned. print_r("show link:". $urls[$i]."<br>"); shows all urls in the form, but the print_r("show current_url:". $current_url); shows only the last one. Code: [Select] <?php $urls = explode("\n", $_POST['urls']); $db = new mysqli('localhost', 'root', 'root', 'urls'); if (mysqli_connect_errno()) { echo 'Błąd: '; exit; } for ($i=0; $i<count($urls); $i++){ print_r("show link:". $urls[$i]."<br>"); $current_url = file_get_contents($urls[$i]); print_r("show current_url:". $current_url); preg_match( "/[\._a-zA-Z0-9-]+@[\._a-zA-Z0-9-]+/i", $current_url, $email);//email print_r ("show email:".$email[0]); $zapytanie = "INSERT INTO urle set adres = '$email[0]' "; $wynik = $db->query($zapytanie); } if ($wynik) { echo $db->affected_rows ."pozycji dodano."; } else { echo mysql_errno() . ":" . mysql_error() . "Wystąpił błąd przy dodawaniu urli "; } $db->close(); ?> Hi there, hope one of you can help me with a problem im just having. Ok, lets start with the explanation what i want to to: I'd like to collect headlines from a html site, and get the test results in an array, so that the array structure represents the dom-levels of the site. Small Example: <h1>test1.1<h1/> <h2>test2.1</h2> <h2>test2.2</h2> <h3>test3</h3> <h1>test1.2<h1/> Shoul end in a array structure like: Code: [Select] array('level 1' => array ( 'sibble1' => array ( 'headline' => 'test1.1', 'level2' => array( 'sibble1' => array ( 'headline' => 'test2.1', 'level3' => array(), // empty data, needs to be processed anyway to find gaps, to maybe a h4 headline would be existing ), 'sibble2' => array ( 'headline' => 'test2.2', 'level3' => array ( 'sibble1' => array ( 'headline' => 'test3.1', 'level4' => array(), // empty data, needs to be processed anyway to find gaps, to maybe a h4 headline would be existing ), ), ), ), ), 'sibble2' => array ( 'headline' => 'test1.1', 'level2' => array(), ), ), ); So i hope out of this example you can see what i want to do. level represents the healdine level 1-9, sibblin is as name for the childs on the headline level. Ok, so to extract the herefore needed data out of the html, i build a class with a recursive function, that filters the html by a regex from one headline to the next, first iteratin all childs, if there are no more childs i go tho ne nextsibbling element. as an running example code look he Code: [Select] <?php class Application_Model_DomParser { const PREG_MATCH_ONE_ELEMENT_TO_MUCH_LENGTH = 4; private $slicedFields = array(); public function __construct() { } public function sliceFirstSectionToDataFields($level = 1, $haystack) { preg_match_all("#(.*?)<h$level>(.*?)</h$level>(.*?)(<h$level>|$)#s", $haystack, $data); // prepare the chunkData $pageText = ''; if (isset($data[1][0])) { $pageText = $data[1][0]; } $headline = ''; if (isset($data[2][0])) { $headline = $data[2][0]; } $dataToProcessNextLevel =''; if (isset($data[3][0])) { $dataToProcessNextLevel = $data[3][0]; } // @todo dirty warnings compression, search why warning occures @$posOfNextChild = strlen($data[0][0]) - self::PREG_MATCH_ONE_ELEMENT_TO_MUCH_LENGTH; // from here goes the debug... echo $headline ."::" .strlen($dataToProcessNextLevel). "<br>"; if (strlen($dataToProcessNextLevel) <= self::PREG_MATCH_ONE_ELEMENT_TO_MUCH_LENGTH) { if ($level < 9) { $dataToProcessNextLevel = $haystack; } else { return; } } //recursive check for next level in $dataToProcessNextLevel $nextLevel = $level + 1; $this->sliceFirstSectionToDataFields($nextLevel, $dataToProcessNextLevel); $haystack = substr($haystack, $posOfNextChild); // slized To The End if (self::PREG_MATCH_ONE_ELEMENT_TO_MUCH_LENGTH == strlen($haystack)) { // die("slized To The End"); return; } // recursive check for other childs in actuall level... $this->sliceFirstSectionToDataFields($level, $haystack); } } $htmlString = 'test<h1>headkline1.1</h1> <p>test test</p> <h2>headline 2.1</h2>test test <h2>headline 2.2</h2> <p>tes test test</p> <h3>headline 3.1</h3>test <h3>headline 3.2</h3>test <h2>headline 2.3</h2> <p> </p> <p>test</p> <h1>headline 1.2</h1> <h2>headline 2.4</h2> <p>11111111111112222222222222222222222</p> <p> ewfwrefg upowmdg w3q09umq09wrt n3q089ty 3q0898943ty -98 41</p> <h3>headline 3.3</h3> <p>test</p> <p>test</p> <p>test</p> <h1>1.3 testtest</h1> <p>test</p> <h3>head 3.4</h3> <p>sadfsadfsadf asdfsda f sdaas saf saddas</p> <h3>head 3.4</h3> <h3>test 1.3</h3> <p>test;</p> '; $model = new Application_Model_DomParser(); $result = $model->sliceFirstSectionToDataFields(1, $this->htmlString); So letting this piece of code run, you can se via the debug echo, every headline is found, even in the right order of its occurence. My problem now is dont get it how to return the extracted values, and collect them to get a result as my above shown structure shows. So i spent ours to solve this problem but didnt come to a result. I know its a hard problem, and to help me takes time, cause its a complex situation. Allthough i hope someone knows a anser. I need this problem solved, to get my mind rested! Thanks, and greetings Selma I am really lost here with this date issue of mine. The below code is the last part of a query: Code: [Select] $defendercheck_3 = $row_checkifattacked3['atdate']; $defendercheck1_3 = strtotime("$defendercheck_3"); $defendercheck2_3 = date("D", $defendercheck1_3); The query does not return any results as expected, but when echoing the various steps I get following: echo "$defendercheck3"; = nothing (as expected) echo "$defendercheck1_3"; = nothing (as expected) echo "$defendercheck2_3"; = result! (NOT expected) why does it return anything on "date("D", $defendercheck1_3)" when "$defendercheck1_3" is blank? hey, im trying to show data in a text box thats being retrived from a database, but if there is a ' in it, it will only show the text up to that point. (ie. if it has "You're" it will only show "You") here is the code im using echo "<input type='text' value='$picComment'>"; Hi, my site is displaying something weird, http://86.21.243.231/ on the table at the bottom, it should list the amount of tickets sold. if the user deposits 0.3, then it should display 3 seperate rows for 0.1 with their payout address. but for 0.3, it displays 2 rows of 0.15 instead. the code for the table is: Code: [Select] $sql="SELECT * FROM tickets WHERE `round` = '$round' AND `confirmed` = 'yes' ORDER BY timestamp ASC"; $result=mysql_query($sql); $row=mysql_fetch_array($result); $result=mysql_query($sql); while($row = mysql_fetch_array( $result )) { $ticketamount = $row['amount']; $ticketspurchased = (int)($ticketamount / $ticketprice); $ticketamount = $ticketamount / $ticketspurchased; for ( $counter = 1; $counter <= $ticketspurchased; $counter += 1) { $i++; echo "<tr><td>"; echo $i; echo "</td><td>"; echo $row['address']; echo "</td><td>"; echo $ticketamount; echo "</td><td>"; echo $row['confirmed']; echo "</td><td>"; echo $row['timestamp']; echo "</td></tr>"; } } 0.5 shows correctly Any ideas? This topic has been moved to CSS Help. http://www.phpfreaks.com/forums/index.php?topic=309496.0 |