Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
 
  HOME    TRACKER    PHP




How To Add A <br> After 3 Results?


I am wondering if anyone could help me solve this issue. I am using a foreach loop and i would like to add a line break after three records then repeat the process.

Example:

foreach($array as $v){
echo $v.' ';}

In that example, it will display ( apples oranges banana pumpkin turnips pineapple beer pepsi) How do i get it to display:

apples oranges banana
pumpkin turnips pineapple
beer pepsi etc....

Notice above that after each three results the next three are placed on a new line. How can I accomplish that with my loop.




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
Search Brings Back Different Results Or Sometimes No Results
The problem Iv got is that when searching the site - it brings back different results or sometimes no results. For example: "i026", "i 026" and "026" do not bring back results for "I-026" which is the correct model number. Any ideas on how to make it search more variations or of a "Did you mean... I-026" script?

Search Results ($num_rows) Does Not Match $search Results (PHP,MySQL)?
For example, when I do a database search for a term I get 2 results but the $num_rows says there are 3 results.

I suspect it's because there are similar keywords within different search fields of the SQL statement. But I am stumped as to how I can change this. Any Suggestions? the code:

Getting Results Twice?
I am having a small problem. I have a small script which gets a METAR feed, processes it and then displays the weather information. The problem is that it will accept 1 weather station as an input variable.

How can I run this script TWICE within the same execution, while getting 2 results, using 2 different weather stations? The main file uses this to execute the functions which are on another separate file: Code:

Splitting Up Results
I have a large database and would like to split the results into 20 per page and with arrows to go to the next page and numbers to skip pages. But I'm not sure how to do it. I know I've seen an article on how to do this somewhere, anyone know one about this?

Is This Possible With Search Results
Is it possible that when someone does a search on your database, that the results are downloaded as a text file?

Grabbing Only First Var From Results
I'm working on a calendar program that I inherited from a sick Webmaster somewhere in the world. Below is part of the code that chooses and compares dates to print on the calendar. The part in bold is what I think is going to be the key to solving my problem, I just don't know how to go about it.

The 'dates' column for a record in the 'programs' look like this: &62&74&84&90, etc.

Each number represents a date with more details in the 'dates' table.
Echoing out $datenum will give one number like &#3963;'. The problem is I want only first date and to ignore the rest per record. The SQL looks like this. Is it possible to only get the first search result of date per record?

foreach ($chosen_dates as $c) {
if ($c['day'] == $day_num) {
if ($section == false) { // This runs for printing courses and not programs
$coursenum = $c['coursenum'];
$name = mysql_query("SELECT name FROM courses WHERE keyword='$coursenum'");

$name_row = mysql_fetch_object($name);
// if there are courses for this $day_num

print "<p><a href='course.php?index=".$c['coursenum']."'
";

print "title='".$c['stime']."-".$c['etime']." ".$c['section']."'>".$name_row->name."</a></p>
";
}
else { // This runs to print programs and not courses.

$datenum = $c['datenum'];
echo "Datenum=$datenum";

$date_search = mysql_query("SELECT num, dates, category FROM programs WHERE dates REGEXP '&$datenum&'");

$date_found = mysql_num_rows($date_search);
//echo "Number of dates found = ".$date_found;

if ($date_found > 0) {
while($row = mysql_fetch_object($date_search)) {
//echo $c['section'] ." ";
//echo "cat= ". $row->num;
foreach($isPrinted as $printed){
if(!in_array(array('section'=>$c['section'], 'courseNum'=>$row->num), $isPrinted)){
print "<p><a href='program.php?index=".$row->num."'
";
print "title='".$c['stime']."-".$c['etime']." ".$c['section']."'>".$row->category."</a></p>
";
$isPrinted[] = array('section'=>$c['section'], 'courseNum'=>$row->num);
break;
}

}
}...

Is there such thing as maybe using a LIMIT with this kind of SQL statement? The one above is:SELECT num, dates, category FROM programs WHERE dates REGEXP '&$datenum&

Could you use something to the effect of:
SELECT num, dates, category FROM programs WHERE dates REGEXP '&$datenum& LIMIT 1?

Listing Results From DB
Anyway I have a wee problem: what I have is a javascript popup with two values passed through: PHP Code:

Results Into A Matrix Using Php?
I've been trying to work out how to insert results from a database query into a two-dimensional matrix using php.
We used a star schema for our datawarehouse. Thus we have a price fact table and we need to perform aggregate functions on this table. This part is relatively simple.
I've managed to connect to the oracle database and retrieve the data but only display the results in a normal table. What I'd like to do is display the results in a matrix so that I can avoid repeating fields. For instance if there are three variables: Code:

Checkboxes And Sql Row Results
I am trying to place a checkbox beside each row that is inputed into the database.

Now this is how I diplay the rows:
print "<br><br>There are $num_rows records.<P>";
print "<table width=500 border=0>
";
while ($get_info = mysql_fetch_row($result)) {
print "<tr>
";
foreach ($get_info as $field)
print " <td><font face=arial size=1/>$field</font></td>
";
print "</tr>
";

How would I go about attaching this:
<input type="checkbox" value="..." name="...">
to the side of each displayed row? Also, how would I assign the row id to the checkbox so that once the box is check and the action initiated the row would be deleted?

Returning Results With An '
I am using this script

$mresult = mysql_query("SELECT DISTINCT game FROM vids order by id desc limit 50", $link) or die ("query 1: " . mysql_error());

while ($mrow = mysql_fetch_array($mresult))
{
$count = mysql_result(mysql_query("SELECT COUNT(*) FROM vids where game = '$mrow[game]'"), 0);
}

but for any $mrow[game] that has an ' in it a 0 is returned, how do I fix this?

Getting Bad Results From Fsocketopen
If I send this to the server:

POST /errors/index.htm HTTP/1.1
Host: www.publicdomainsoftware.org
Content-Type: application/x-www-form-urlencoded
Content-Length: 1200
%3C%2Fdiv%3E

Why do I get this back:

HTTP/1.1 400 Bad Request Date: Fri, 12 May 2006 02:37:43 GMT Server:
Apache/2.0.46 (Red Hat) Content-Length: 302 Connection: close
Content-Type: text/html; charset=iso-8859-1
Bad Request
Your browser sent a request that this server could not understand.
Apache/2.0.46 (Red Hat) Server at default Port 80

Sorting XML Results
The following code parses an XML file and displays the results. The function resultSort is meant to sort the results by price from highest to lowest. Unfortunately, it's not sorting correctly in all cases. I think this may be due to the prices being in euros. Right now, this is how it outputs the results:


1 208,00
2 148,00
412,00
638,00
942,00

This is how it should look:

2 148,00
1 208,00
942,00
638,00
412,00

Here's the code: PHP Code:

PHP - Sending Results
I am looking for a simple form Processor that will send the results to a defined user, but at the same time send these same results to the user that filled it out. This sounds simple enough I realized, but to be honest I can't seem to find anything that will easily allow me to do this and use my own HTML based inputs at the same time.

Sorting Results
I hava a table with a primary key cod_topico and I'd sort my results.
I do this, ok?
$query='SELECT * from topico order by cod_topico asc' ;
But I would not sorting asc, How I sort a non-asc form? What is the oposite of asc?

Percentage Of Results
I have a table with various colums that I would like to display some stastisics. For example on colum is Gender. It holds either Male or Female. How can I output the percentage of each? ie... Female = 80% Male = 20%

Saving Php Results
I have an html code which contains callings to a php script which generates JPEG images
via GD library. When I select 'save as' in any browser two options are given (.html or .txt) but none of them allows to save the page as it is shown in the browser (with images). Where images should be there are only empty links....Does anyone have an idea about it?

Looping Results...
I'm writing a simple display page for a bunch of info from a realestate database as an exercise. I've successfully queried and displayed the information in tables, but I want it to keep pulling information from the tables until there are no more left. What i've got only pulls one entry. Code:

Getting Too Many Results From A Query!
This is very peculiar -- for some reason, I'm getting 6-8 results from each
of these queries, although only one listing matches. I have a pair of forms
on one page:

<FORM>
Search for lastname: ____________ [Submit]
</FORM>
<FORM>
Search for email: ________________ [Submit]
</FORM>

This goes to a searchresults.php page:

if ($searchname !== "") {
$query="SELECT artistID,firstname,lastname,email,city,state,count ry
from artists WHERE lastname='$searchname'";
$result=mysql_query($query) or die(mysql_error("Could not execute
query."));
while($row = mysql_fetch_array($result)) {
$alt_artistID = $row['artistID'];
$alt_firstname = $row['firstname'];
$alt_lastname= $row['lastname'];
$alt_email = $row['email'];
$alt_city = $row['city'];
$alt_state = $row['state'];
$alt_country = $row['country'];
echo "<CENTER><HR>".$alt_artistID."<BR>"
.$alt_firstname." ".$alt_lastname."</A><BR>"
.$alt_email."<BR>"
.$alt_city.", ".$alt_state." ".$alt_country."<BR>
<A HREF=delete.php?aritstID=".$alt_artistID.">DELETE THIS
LISTING?</A><BR></CENTER>";
}
}

The second section is identical except for:
if ($searchemail !== "") {
$query="SELECT artistID,firstname,lastname,email,city,state,count ry
from artists WHERE email='$searchemail'";
etc...
}

I don't understand why I would get 6-8 records when you can look at them and
see that all but one clearly do not match...?

Paging Through Results
Does anyone have or know of a nice PHP class or code to page through a set of results drawn from mysql? ie to display the list of results in 'pagefuls' with a nav bar like: Code:

[1] [2] >3< [4] [5] where &#393;' is the current page, and the other numbers are links to the other pages...? I know this has been covered a few times on this forum, but I can't for the life of me find any of the threads searching on 'pager' or 'pagination'.

Confusing >> Results
Using >> normally shifts bits to the right x number of times, where x
is specified by the programmer. As an example, 0x40000000 >> 8 yields
0x00400000. This makes me wonder... why doesn't the same thing happen
with 0x80000000 >> 8? The number it yields is 0xff800000 - not
0x00800000. The following script better demonstrates this:

<?
echo sprintf('%08x',0x40000000 >> 8)."
";
echo sprintf('%08x',0x80000000 >> 8);
?>

Sorting Results
What I need to do is from the query I send sort the results by ID numbers from highest to lowest, because the highest number is the most recent news post I would like this to be printed first and then the lower the ID number the further down the post goes. Am I making sense? PHP Code:

OCI - Double Results?
to work with the example for OCI... and the $row returns 2
values, the same twice, but my query only have one... code below.

$query = 'select distinct(something) from a.b'

$stid = oci_parse($connX, $query);
if (!$stid) {
$e = oci_error($connX);
print htmlentities($e['message']);
exit;
}

$r = oci_execute($stid, OCI_DEFAULT);
if (!$r) {
$e = oci_error($stid);
echo htmlentities($e['message']);
exit;
}

print '<table border="1">'
while ($row = oci_fetch_array($stid, OCI_RETURN_NULLS))
{

print '<tr>'
print "<td>".(count($row))."</td>";
foreach ($row as $item) {
print '<td>'.$item.'</td>'
}
print '</tr>'
}
print '</table>'

oci_close($connX);

Numeric Results
I have a mysql quote database and a php page that calls the results...everything is fine except for when I get the results back there are too may 0's on the ends of my numbers ie

220.45000000 and I want it to show 220.45 Can someone have a look at my code and maybe alter it to produce the results I want, I have been at this know for 3 days and because I am a newbie I am finding it difficult.. Code:

Is Anyone Else Able To See My Search Results?
Here is the thing. When you go to this page:

http://www.accumulist.com/index.php...llFields%5D=api

I've put in some HR tags in the HTML to separate the 3 different
queries. After those 3 queries you'll see results at the bottom. For
me, those results look like this:

api (4), darren (1), xml (12), battlepanda (1), war+on+drugs (6),
stupid (1), moron (1), nightmare (1), hell (1), mijkuynbvfsds (1),
police (1), Pitchfork+Media (1),

There are two problems here. Do you get this when you go to this page?
I'm concerned that I'm only getting back the things that I have
personally searched for, and not the things that others have searched
for. Let me know, please, if this works for you.

The goal of this script is to be able to say to the person who is
searching "People who searched for this item, also searched for these
other things."

It is suppose to be a little like on Amazon.com, where when you buy one
thing, it says "Customers who bought this item also bought these other
items:".

I'm sorry I didn't give the table structures earlier. The visitor id of
searchHistory is the id of visitors. machineId is a unique value
generated and set by a cookie.

#
# Table structure for table `searchHistory`
#

CREATE TABLE `searchHistory` (
`id` int(11) NOT NULL auto_increment,
`query` text NOT NULL,
`visitorId` int(11) NOT NULL default &#390;',
`domain` varchar(255) NOT NULL default '',
PRIMARY KEY (`id`)
) TYPE=MyISAM AUTO_INCREMENT=88 ;

#
# Table structure for table `visitors`
#

CREATE TABLE `visitors` (
`id` int(11) NOT NULL auto_increment,
`date` int(11) NOT NULL default &#390;',
`ipAddress` varchar(15) NOT NULL default '',
`hostname` varchar(255) NOT NULL default '',
`machineId` varchar(255) NOT NULL default '',
`referrals` varchar(255) NOT NULL default '',
PRIMARY KEY (`id`)
) TYPE=MyISAM AUTO_INCREMENT=8236 ;

Display Results
I have created a form where the number of rows are displayed based on a value from a select box. Everything works excellent this far. however I need to take it to the next step where I display the information back into the form based on values in a mysql table. Code:

SQL Split Results
I was just wondering. Lets say I have for example, 50 links in a database. How would I make it so it lists all the links in the database but only 10 links per page?

PHP To Echo Results
This may seem very complicated, but I have a list of members from student council. Each has a record of attendance in their own column. (Each row is a different meeting). How can I query the database with php to count how many e's u's and p's there is in a column? How can I do a simple loop to do this and repeat it over many times?

e stands for excused
u stands for unexcused
p ............. present

Reversing Results
Does any one know how I can reverse the results of my search so that the latest one is shown first, i.e. so that it goes from entry 30 to entry 1. Code:

Limit Sql Results
I am working on a site to display thousands of results....I have all of that working but I want to limit the results to 50 at a time...any suggestions on how to browse the results with a limit of 50....I am thinking about checking the value of a number and while it is less than the total count of rows in the query increment it by 50..

Storing Results For Later Use?
Is it possible to store results that are parsed from an xml file and then use them on a different web page? Basically I want to store the data within the nodes and then use that data on another web page. Kinda like adding pagination but instead of gettign the info from a db I am getting it from a xml file. Code:

Adding Results.
I need to add a bunch of results coming from a DB. I tried doing a simple while statement with a plus sign, but that failed because all it's doing is echoing all the numbers =O! Code:

Duplicate Results
I'm fairly new to PHP and after some trial and error managed to get the rsults I want from the following script, except that now some of the results are being duplicated. Code:

Getting Results From A Function?
I have the below function that will return an array of results as its return value. Basically I just want to know how I retrieve each result in the array and print to screen. I thought it was something like echo $row[1], $row[2] ...etc but that doesnt seem to work. Code:

Filtering XML Results
I'm in the process of creating a page that displays multiple lines of inventory for a bunch of products (let's call them 'widgets'). The widgets are listed in XML format (they'll end up being pulled from a MySQL DB eventually). Code:

Using Query Results
Can you use a queries results only once? In this script I'm looping through a query and saving some values in an array. A little further through the script I need to use the same query for output. When I loop through nothing is echo'd to the browser. When I output a row count it shows that the correct number of records, so they must still be there.

Having Different Results On Same Page
I have a database that I would like to use to display the contents in different lists on the same page. In other words, I would like a list of the latest 15 entries in the database to appear in list...then I would like the next 15 to appear on the same page but in a different list structure, etc. I have this so far, but it only displays the latest 15...I am stuck on how to get another list generated from the same query: Code:

Search Results
whenever i do a $result-$row query and try to list the results with a while statement, it always cuts off the first result. how do i fix this?

Ordering SQL Results
How do I order my sql results in descending order?  This is my query:
mysql_query("SELECT * FROM members order by uid limit 1 descending");

Pow() Function Gives Varying Results
I got the following code which works perfectly on my development machine(Windows with PHP 4.3.2) but doesn't give appropriate results on my clients server(linux with PHP 4.2.2). The actual result for $degrees should be 22.9458.... and my clients server fails on giving a result which results in a broken image. Can anyone spot what in that calculation is wrong ?

    

Use Arrays To Page Through Results?
I've got a search facility that interrogates an SQL database then shows the results 30 at a time. Currently, when you go to the next page of results it has to run the query all over again, because there is no way of handing the resultset to the PHP file. So I wondered if there was another way of doing it.

I'm tempted to use mysql_fetch_array and create a multi-dimensional array full of result rows, then hand that around, but so far cannot find out how to hand a PHP array as a variable to a PHP page.

IS this possible, or am I barking up the wrong tree? Or is there a better way of doing this?

Links From Search Results
Hi i was wondering if anybody could tell me how to make url links to an item in my site from a list of search results. Here is a piece of my code:

<?php
$Name = $HTTP_POST_VARS["query2"];
$Eventtype = $HTTP_POST_VARS["query2"];
$EventStart = $HTTP_POST_VARS["query2"];
$EventEnd = $HTTP_POST_VARS["query2"];
$VenueName = $HTTP_POST_VARS["query2"];
if($Name or $Eventtype or $EventStart or $EventEnd or $VenueName)
{

$conn=@mysql_connect("mysql", "u0rr")
or die("Sorry can't connect to database");

$rs = @mysql_select_db("u0rr", $conn)
or die("Sorry can't connect to database");

$sql="select * from event left join venue on
(event.VenueID = venue.VenueID)
where (Name like '%$Name%'
or VenueName like '%$VenueName%')
AND Eventtype = 'Comedy' ";
$result=mysql_query($sql,$conn);

while( $row = mysql_fetch_array($result) )
{
echo("<b>"." Event Name: "."</b>".$row["Name"]."<br>");
echo("<b>"." Event Type: "."</b>".$row["Eventtype"]."<br>");
echo("<b>"." Venue Name: "."</b>".$row["VenueName"]."<br>");
echo("<b>"." Event Start: "."</b>".$row["EventStart"]."<br>");
echo("<b>"." Event End: "."</b>".$row["EventEnd"]."<br>");
echo("<b>"." Availability: "."</b>".$row["Availability"]."<br>");
echo("<b>"." Description: "."</b>".$row["Description"]."<br><hr>");
}
}
?>
For example if i enter an event type as 'comedy', a list of search results will come up from the form input displaying comedy events. Now from these results i would like to be able to click on Venue Name and this would link to that page in another part of my site.

I hope this explanation is o.k, if not post a thread & i'll try and explain a bit better. Thanks for any help

MySQL Results Not Working So Hot
Ok. Here I am again....probably posing a question with a solution so easy that, after looking at it for an hour, I can't figure out. Ok. here's the deal. please review the code below. Looks simple enough, right?

Getting The Right Results Of Count(distinct(col)) Into Php
Hi guys,

I've got the following query, which works from the command line in mysql:


mysql> select count(distinct(col)) from table where userid = 1;
+-----------------------------+
| count(distinct(col)) |
+-----------------------------+
| 96 |
+-----------------------------+
1 row in set (0.07 sec)

Which works as I want it, though I am unsure of how to bring that back into something I can use in PHP... when I do a count, I usually use something like this:

$count = @mysql_query("SELECT count(*) FROM table where [clause]");

And use:
$total = mysql_result($count, 0, "count(*)");

To get the total back. However, if I use:

$count = @mysql_query("select count(distinct(col)) from table where userid = 1;");

And this:
$total = mysql_result($count, 0, "count(distinct(col))");

I get back 198 - which is the total number of entries, not 96, which is the number of unique topics the user has posted to.

To give you an idea of what I'm trying to do: the number I'm after is the number of topics in a bbs system a user has posted to - of course, a user can post to the same thread repeatedly, and in this instance, counting the number of posts as opposed to the number of topics the user has posted to, is not what I'm looking to do....... Any thoughts? :/

Scrolling Results In Includes
I've picked up the development of a php/mysql driven site that uses a header, main and footer include to assemble the page. The main include being either static information pages, or Product details built up from queries to mysql.

You can take a look at URL ....there is a holding page on the root so index.php is required.

In order to maintain maximum navigation functionality, the client has requested that the displayed product results are scrollable in the center of the page with the menus etc remaining in place around the outside. The area in which the products are displayed is, again, an include, not a frame.

So in a nut shell, I'm looking for a custom scroll solution in an include.

Navigating Multiple Results?
Hi all, whats the best way to navaiagte multiple page of results.

<Previous 1 2 3 4 Next>

What SQL is needed to do a limit that starts in the middle of a returned set.

SELECT * FROM table LIMIT BETWEEN 20 TO 50;

Email Form Results
I have a form and I need the results emailed to me how would I be able to do this.

Printing CURL Results
I am trying to have php return the result from curl by creating an html page. I have tried a number of different ways but keep coming up with just a blank page. I read that it may be the buffer amount required by IE6 so I tried formatting for that, here is the code, let me know if there are suggestions, thanks.

<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<?
$ch = curl_init("http://www.yahoo.com");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$info = curl_getinfo($ch);
$result = curl_exec ($ch);
curl_close ($ch);
if (isset($info)){
echo ($info);
print str_repeat ("", 1000) . "
";
}
?>

</body>
</html>

I have also tried taking the output buffering approach, like this, but it still didn't work after I tried to then use string functions to format any html in between the <body> tags of the variable from curl.

ob_start();
$result = curl_exec($ch);
return $result;
curl_close($ch);
$retrievedhtml = ob_get_contents();
ob_end_flush();

Form Results To Email
Im very new to PHP and so this might seem like childsplay to some people.

Ive got a form on a web page, with different fields.

When the user clicks on submit, I want the fields that they have filled in, to be emailed to me with the structure of the form.

The purpose of the form is so that the users of my site can submit written articles to my email.

Formatting SQL Results In Tables
Fairly new to all this, but, I can return results from MySQL into a table without any problems - but what about formatting.

I need the 6 columns to be of fixed width. Currently, due to the variable length of the data in the columns, they keep changing each time I cycle through a set of results.


Copyright © 2005-08 www.BigResource.com, All rights reserved