473,382 Members | 1,380 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Printing results from query

Greetings.

I have some problems which is not surprise as I'm a beginner in PHP.

Here is my problem.

I created database and table named base and news.
In table news I created column: id, title, text, all_text, date... and category.

I want to display last news by id and category. I used this:

while($row = mysql_fetch_row($result)) {
$title[$i]=$row[1];
$text[$i]=$row[2];
$date[$i]=$row[4];
$category[$i]=$row[6];
...........


$i++;


Well, this would print news as they were written.

But, I want to print news from certain category, I used this:

for($i=0;$i<sizeof($category);$i++) {
if($category[$i]=="Art")

$title2[$j]=$title[$i];
$txt2[$j]=$text[$i];
$date2[$j]=$date[$i];
......

$j++;

It worked well printing news from "ART".
But after this, I want to print news from category SPORTS.

How I'll do this? Please someone :(
Sep 2 '06 #1
6 1935
This doesnt work at all.

It prints all news and not from ART category.

:(
Sep 2 '06 #2
Banfa
9,065 Expert Mod 8TB
You have your data in a database but are trying to sort it yourself.

This is the proverbial having a dog and barking yourself.

In your SELECT statement use a WHERE clause to filter on the category that you wish to use, forget about trying to do this kind of sort yourself.
Sep 2 '06 #3
Ok, but I want to display 5 news from category, than 5 new from other category, and so on.
Sep 3 '06 #4
I found the solution.
Sep 3 '06 #5
Can you please post the solution here so that everyone can be benefitted out of it ?

I have a solution in mind but i am not very sure if it will work.
I want to see your solution first.

Rahul Agrawal
Developer
Web2003 Corporation
www.web2003corp.com
Sep 4 '06 #6
Can you please post the solution here so that everyone can be benefitted out of it ?

I have a solution in mind but i am not very sure if it will work.
I want to see your solution first.

Rahul Agrawal
Developer
Web2003 Corporation
www.web2003corp.com
Ok, the solution I came to is to have separate queries for each category i want to display news from.
It can be made in more efficient way, but hey! I'm not fimiliar with PHP. It could be done trough WHILE, IF, ELSE and FOR. but...

So,
I made this:

$query1 = "SELECT * FROM news WHERE category='arts' ORDER BY id DESC LIMIT 5";
$query2 = "SELECT * FROM news WHERE category='politics' ORDER BY id DESC LIMIT 5";

than defined variables to carry values from selected rows, than print them.
variable $title for first category will be equal to =row[1]
but $title for other category will be - $title1[$i]=row[1]

maybe modest, for some stupid, but it works for me!
Sep 5 '06 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Marko | last post by:
Hi, I would like to print results from web query written in php on printer(HP). The problem is that I need to exactly define margins for each variable to print (TAX forms etc.). I`m new at php....
9
by: Jody Gelowitz | last post by:
I am trying to find the definition of "Safe Printing" and cannot find out exactly what this entitles. The reason is that I am trying to print contents from a single textbox to no avail using the...
3
by: Par-breaker | last post by:
Is there any way to send the results of a query executed within a stored procedure to the default windows printer, or even to a text file? (I thinking of something similar to Oracle's DBMS_OUTPUT,...
4
by: John Baker | last post by:
Hi: I have a form, which contains a sub form (Employee main record and payment record). It all shows up fine in a screen view, but when I come to print it I find that I cannot get the sub form...
5
by: Wayne Aprato | last post by:
This is probably very simple but: How do I print an open form to the default printer. I want the user to click a button on the form and have it print without them having to bother with the print...
4
by: Sami | last post by:
I hope someone will tell me how to do this without having to do any VB as I know nothing in that area. I am a rank beginner in using Access. I have created a database consisting of student...
2
by: Edward | last post by:
Hello, everyone, My application needs some print functions , such as Print Invoice, Print Query Results, or Print Charts. I'm sure most of you must have the experience, would you please do me...
1
by: JackM | last post by:
I'm not sure if this qualifies as a mysql or a php question so I'm asking in both groups. I am pulling the results of a mysql query from my database and want to print the results into a two...
0
it0ny
by: it0ny | last post by:
Hi guys, thanks I am fairly new to this forum so I hope I chose the right place to post this question. I try to make my program printout a deposit's report. I created a class to store the...
3
by: jmooney5115 | last post by:
Hey. I am new to php and am trying to learn. What I'm doing is querying(did I spell this right?) a mySQL database and putting the results into a table on a webpage. I have worked for hours on this...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.