PHP - Moved: Pull Specific Data From Sql And Group It (best Way I Can Think To Put It)
This topic has been moved to Microsoft SQL - MSSQL.
http://www.phpfreaks.com/forums/index.php?topic=347695.0 Similar TutorialsHi, im looking to pull 3 posts from a specific Wordpress Category. At the minute I can pull 3 latest posts and display them in a flash banner using the code below. Code: [Select] SELECT yah_posts.*, yah_postmeta.* FROM yah_posts LEFT JOIN yah_postmeta ON yah_posts.ID = yah_postmeta.post_id WHERE yah_postmeta.meta_key = 'largeimage' && yah_posts.post_status = 'publish' ORDER BY post_date DESC LIMIT 3 I want to be able to pull 3 latest posts from a specific category instead of just 3 latest posts from every category. I have put together this code below, but it doesn't seem to be working Code: [Select] $query = "SELECT yah_posts.*, yah_postmeta.* FROM yah_posts LEFT JOIN yah_postmeta ON yah_posts.ID = yah_postmeta.post_id AND LEFT JOIN $yah_term_taxonomy ON($yah_term_relationships.term_taxonomy_id = $yah_term_taxonomy.term_taxonomy_id) WHERE yah_postmeta.meta_key = 'largeimage' && yah_posts.post_status = 'publish' AND $yah_term_taxonomy.term_id = '1' AND $yah_term_taxonomy.taxonomy = 'category' ORDER BY post_date DESC LIMIT 3"; Hi all, I would like to ask you if somebody could have a better idea to build this function. The current one is working, but I feel this built a bit in an amateur manner. Feel free to add your ideas so we can learn more about PHP and how to deal with arrays.
I have an array: $arrayVideoSpecs = Array( Array( 'aspect' => '4:3', 'density' => '442368', 'resolution' => '768x576' ), Array( 'aspect' => '4:3', 'density' => '307200', 'resolution' => '640x480' ), Array( 'aspect' => '16:9', 'density' => '2073600', 'resolution' => '1920x1080' ), Array( 'aspect' => '16:9', 'density' => '121600', 'resolution' => '1280x720' ) );
and I want an array as output grouped by video aspect ratio where the key is the pixel density and the value is the video resolution, namely like that for aspect ratio 16:9 ... Array ( [2073600] => 1920x1080 [121600] => 1280x720 )
Then I coded this function which is working but seems amateur ... function groupAndExtractByAspect($array, $groupBy, $aspect, $density, $resolution) { $groupByAspect = Array(); foreach ($array as $value) { $groupByAspect[$value[$aspect]][] = Array($value[$density], $value[$resolution]); } $arrayClean = Array(); foreach ($groupByAspect as $key => $value) { if ($key == $groupBy) { $arrayClean[$key] = $value; } } foreach ($arrayClean as $aspectGroup) { $arrayOutput = Array(); for ($i = 0; $i <= count($aspectGroup); $i++) { $densityIsValid = false; $resolutionIsValid = false; if (!empty($arrayClean[$groupBy][$i][0])) { $density = $arrayClean[$groupBy][$i][0]; $densityIsValid = true; } if (!empty($arrayClean[$groupBy][$i][1])) { $resolution = $arrayClean[$groupBy][$i][1]; $resolutionIsValid = true; } if (($densityIsValid === true) && ($resolutionIsValid === true)) { $arrayOutput[$density] = $resolution; } } } return $arrayOutput; }
The usage is as follow ... $showArray = groupAndExtractByAspect($arrayVideoSpecs, '16:9', 'aspect', 'density', 'resolution'); echo '<pre>'; print_r($showArray); echo '</pre>';
Thank you very much for your ideas! Mapg Hi, I want to pull data from db, where sometimes all rows and sometimes rows matching given "username". Here is my code:
//Grab Username of who's Browsing History needs to be searched. if (isset($_GET['followee_username']) && !empty($_GET['followee_username'])) { $followee_username = $_GET['followee_username']; if($followee_username != "followee_all" OR "Followee_All") { $query = "SELECT * FROM browsing_histories WHERE username = \"$followee_username\""; $query_type = "followee_username"; $followed_word = "$followee_username"; $follower_username = "$user"; echo "$followee_username"; } else { $query = "SELECT * FROM browsing_histories"; $query_type = "followee_all"; $followed_word = "followee_all"; $follower_username = "$user"; echo "all"; } }
When I specify a "username" in the query via the url: browsing_histories_v1.php?followee_username=requinix&page_number=1 I see result as I should. So far so good.
Now, when I specify "all" as username then I see no results. Why ? All records from the tbl should be pulled! browsing_histories_v1.php?followee_username=all&page_number=1 This query shouldv'e worked:
$query = "SELECT * FROM browsing_histories";
I need to pull all the mysql data by the order of it's date/time . How can I write the code? I'm using this as a serverside script and I'm not a php person. But i believe the below code will not pull the data. Will it work if I remove the text marked in red? $query = "SELECT * FROM sub_db WHERE the_code = '".$abc."'" ORDER BY timestampz ASC"; This is my code. Data is been pulled from db_faq and Db_2 and then match the records against each other using array_intersect(). And as you see the data from db_faq is been pulled based on the $username. My question is how can I ignore the $username and match all rows in db_faq against the data in db_2? Basically I need to get the matching records between the 2 databases regardless of the username. $Array1 = array(); $Array2 = array(); $var1 = '$username'; $query1 = "SELECT * FROM db_faq WHERE username = '".$var1."'"; $result1 = mysql_query($query1); $score1 = mysql_fetch_assoc($result1); foreach (range('25','35') as $ltr) { $Array1[] = array($score1['roundzA' . $ltr]); } $var2 = 'new'; $query = "SELECT * FROM db_2 WHERE place = schedule"; $result = mysql_query($query); $score2 = mysql_fetch_assoc($result); foreach (range('25','35') as $ltr) { $Array2[] = array($score2['points' . $ltr]); } $count = array(); for($i=0;$i<count($Array1);++$i) { $count[$i] = count(array_intersect($Array1[$i],$Array2[$i])); } $countResult = array_sum($count); This is the link to pull the page http://127.0.0.1/kudos/?viewkudoid=### This is the kudo-function.php page function get_kudo_info($viewkudoid){ global $wpdb; $tablename=acikudos_table_name(); $viewsql = "SELECT * FROM $tablename WHERE kudoid='$viewkudoid'"; $viewresult = $wpdb->get_results($viewsql); #$vewrow = mysql_fetch_assoc($viewresult); return $viewresult; } This is the kudo-view.php page function show_kudos($viewkudoid) { global $wpdb; $viewkudoid = $_GET['viewkudoid']; $getthekudo = get_kudo_info($viewkudoid); if ($viewkudoid == $getthekudo['kudoid']) { echo 'Congratulations, you have successfully fixed it!'; } else { echo 'Everything is displayed'; } } add_shortcode( 'kudosview', 'show_kudos' ); I know the issue is right in front of me but I can not find it. I am getting an error on line 3 for the original code, so I need help there, but what I do have a question on is this: http://kaboomlabs.com/PDI/test2.php Code: [Select] <?php $dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME) $result = $mysqli_query("SELECT * FROM comp"); echo "<SELECT name='comp'>\n"; while($row = $result->fetch_assoc()) { echo "<option value='{$row['name']}</option>\n"; } echo "</select>\n"; $result_close(); ?> What I am attempting to do is two fold. 1. Using PHP create a pull down menu that grabs data from the database. 2. Have something in where after line three there is a dotted break, and then the rest of the list is shown. There are over 150 entities that go into this database, so the top 3 are going to be the most used, the rest are going to be in alphabetical order. Now the database has a auto-increment numbering system, the company name, address, phone number, and email if possible. I only want it to show the company name. Is this possible at all? hello, i have a table in a database that stores information on powerpoint presentations like so: id, title, filename, presenter, program, session I want to query the data so that all entries are grouped by session (which is a date) and each presentation is displayed under its respective session in a table like so: [session] (i want to display each session once) [title] - [program] (then i want to display this information for each presentation in each session) [presenter] [session] [title] - [program] [presenter] etc... i am thinking of using group_concat for this but am not sure exactly how to pull it off. any help is greatly appreciated. thank you! This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=353968.0 This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=306114.0 This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=331465.0 I'm trying to output this: Status Player Player Player Status Player Player Player Status Player Player I tried this, but it didn't work: Code: [Select] while($players = mysql_fetch_assoc($results)) { foreach ($players as $player=>$status){ echo '<div>' . $player['status'] . '</div>'; foreach ($status as $key) { echo $key['playerFirst'] . ' ' . $key['playerLast'] . ', '. $key['year'] . '<br>'; } } } I guess I'm trying to find a more efficient way of doing this rather than if/elseif for each one. Right now, there are only four groupings, but in the future there could be as many 406. This topic has been moved to Miscellaneous. http://www.phpfreaks.com/forums/index.php?topic=342897.0 I have json code and i want to prine only {"currency":"DOGE","available":"0","reserved":"420.000000000"} data. my json data [{"currency":"1ST","available":"0","reserved":"0"},{"currency":"DOGE","available":"0","reserved":"420.000000000"},{"currency":"ZSC","available":"0","reserved":"0"}] I use this code
<?php ?> I am wondering if it's possible to get some data from another website via PHP? I would like to get data from website http://www.gamersfirst.com/warrock/?q=Player&nickname=soldier, and the exact data which I need is "Level" which is in this case 2. Can this value be grabbed and if it can, where can I get some info about how to do it? I'm new to PHP and I have an html page I would like to pull specific data into certain areas on the page that I will modified for php. Here are some details. The page is a static html page that has the prices of 40+ products in a standard <li> list. When I update the prices in our database through our shopping cart, I have to change these prices manually in the html. https://www.novon.co...mic_mixers.html. It would be great if I could link the field for Base_Price in the products table to each affiliated <li> tag, I am pulling all the data I need into ($results) and can display it all but I don't know how to get just the single products Base_Price in my <li> tag. <?=$row['Base_Price'] ?> I know this code is not correct but to get the point across, can I create a variable that I define in each <li> tag with a statement like,,,, <?=$row['Base_Price with Product_Code=123456'] ?> I could create a new SQL query for each <li> like "SELECT Base_Price from Products WHERE Product_Code='123456' ", but that's a lot of calls to the DB and a lot of code on the page. And just so I weed out the hard core coders, I can not rebuild the entire page. This is too big of a project for me and my limited coding with PHP. Can anyone help?? Thanks in advance Michael I am trying to get specific data from a MySQL table but cannot seem to find a proper command. Code: [Select] $link = mysqli_connect('#####', '########', '########'); $user = $_SESSION['username']; $email = mysqli_query($link,"select email from members where username='$user'"); echo $email; Specifically, I am trying to get the email address stored for the user specified by the session, and display that address. However, I do not get any output with the current code, and am not sure what to try next. I have tried mysqli_fetch_row() but it only returns an error. Hi guys ..
please help me .. I don't know how to do this and I tried but there were no satisfied results..
I want to retrieve a Title (ing_title) from a database called k_db2 , in a table called content_langs
depending on its ID , which called ing_contID
example: if ing_contID=1 , then show the ing_title with this id ing_contID
the above code should be in a php file ..
then I want to include this php file inside the header of my website..
by importing the ing_contID from the database and depending on it the title should be shown..
I really tried but I couldn't find any solution ..
if you could help me in the first part of this problem I'll be glad ..
In follow up to my previous post, I have found a way to display my data but now I am wanting to only display certain data (within an 'if' statement). For example, if I login as a particular student and there is three sets of data in there e.g. MATH1023, ENG1003 and ENG1013 but I only want to display the student's MATH1023 data in a section, how do I do this? I know that I need to do some sort of an IF statement where 'crsecode=MATH1023' but for some reason I cannot get this to work without it pulling this along with the two English courses. Here is my code: Code: [Select] <?php $db_host = "locahost"; $db_user = "dbuser"; $db_pass = "dbpassword"; $db_name = "dbconnection"; $dbac = mysql_connect($db_host,$db_user,$db_pass); mysql_select_db ($db_name) or die ("Cannot connect to database."); if (!$_POST['search']){ ?> <form name="Item Search" method="post" action=""> Item Search:<br> <label> <input name="swords" type="text" size="30" maxlength="30"> </label> <br> <label> <input name="search" type="submit" id="search" value="Search"> </label> </form> <?php }else{ $searchwords = addslashes(htmlspecialchars($_POST['swords'])); if (strlen($searchwords) < 2){ echo "Your search must contain at least 3 characters. Please try again.<br><input type=button value='Back' onClick='history.go(-1)'>"; }else{ $words = explode(' ',$searchwords); $totalwords = count($words); $i = 0; $searchstring = ""; while ($i != $totalwords){ if ($i != 0 and $i != $wordcount){ $searchstring .= " and ";; } $searchstring .= "cwid LIKE '%$words[$i]%'"; $i = $i + 1; } $query = mysql_query("SELECT DISTINCT * FROM transferdatafile where $searchstring"); if (mysql_num_rows($query) == 0){ echo "No results were found.<br><input type=button value='Back' onClick='history.go(-1)'>"; }else{ echo '<table border=1>'; while ($row = mysql_fetch_array($query)){ echo '<tr>'; echo '<td>'.$row['firstname'].'</td>'; echo '<td>'.$row['lastname'].'</td>'; echo '<td>'.$row['subj'].'</td>'; echo '<td>'.$row['course'].'</td>'; echo '<td>'.$row['crsecode'].'</td>'; echo '<td>'.$row['crsegrade'].'</td>'; // etc echo '</tr>'; } echo '</table>'; } } } ?> Here is the output that I currently get with this when all I want is MATH1023 to display for this particular student's ID (see attachment). Anyone help? [attachment deleted by admin] Hello All, Please excuse my lack of knowledge in advance, I'm a beginner but pick things up relatively quickly, and tend to do things by trial and error. I would appreciate any help that anyone could offer with the following: I would like to retrieve two pieces of data from a "text file" and use them to calculate a result from a function I have in javascript. An example of the javascript code is: <script type="text/javascript"> function calculate() { var drybulb = document.calc_form.drybulb.value; var relhum = document.calc_form.relhum.value; var answer = ''; if (drybulb !== '' && relhum !== '') { answer = (0.567*drybulb*1) + (0.393 * (relhum*1/100 * 6.105 * Math.exp(17.27 * drybulb / (237.7 + drybulb*1)))) + 3.94; } document.calc_form.answer.value = answer; return false; } </script> Currently this is evaluated with entry from a simple html form, but I would like to have this performed "automatically". The "text file" that I would like to access is here, not on my server: http://www.bom.gov.au/fwo/IDV60901/IDV60901.94870.axf I would like to extract the "air_temp" and "rel_hum" values under the [data] section for use in my function. I just need the "most recent" values (i.e. first), not all those contained in the file. This is a single record from that section (sorry for the mess this no doubt makes): [data] sort_order,wmo,name[80],history_product[80],local_date_time[80],local_date_time_full[80],aifstime_utc[80],air_temp,apparent_t,cloud[80],cloud_base_m,cloud_oktas,cloud_type[80],cloud_type_id,delta_t,dewpt,gust_kmh,gust_kt,lat,lon,press,press_msl,press_qnh,press_tend[80],rain_trace[80],rel_hum,sea_state[80],swell_dir_worded[80],swell_height,swell_period,vis_km[80],weather[80],wind_dir[80],wind_spd_kmh,wind_spd_kt 0,94870,"Moorabbin Airport","IDV60901","27/10:00pm","20120227220000","20120227110000",18.8,19.3,"Partly cloudy",510,3,"-",-9999,0.8,17.5,13,7,-38.0,145.1,1013.5,-9999.0,1013.5,"-","11.4",92,"-","-",-9999.0,-9999,"10","-","S",11,6 Would it be possible to obtain these values using PHP?, and if so any advice on how this could be done (noting my minimal knowledge) would be greatly appreciated. Cheers. |