0

hy i have question i have this code and i whant to print it one by one not all the page the script is

    <?php
    $qry=mysql_query("SELECT * FROM articles order by articles.id DESC ", $con);
    if(!$qry)
    {
    die("Query Failed: ". mysql_error());
    }


    /* Fetching data from the field "title" */
    while($row=mysql_fetch_array($qry))
    {
    echo " <section class=content invoice>   ";      
    echo "<h2>".$row['category']."</h2><br>";
    echo "<input type=submit name=submit id=submit class=btn btn-primary value=Edit onclick=window.location='edit_article.php?id=".$row['id']."'; /> ";
    echo "<input type=submit name=submit id=submit class=btn btn-primary value=Delete onclick=window.location='delete_article.php?id=".$row['id']."';  /><br> ";
    echo "<table class='table table-bordered table-hover'><tr><th>/</th><th>Caricati</th><th>Scaricati</th><th>Diferenza</th></tr><tr><td>carelicc</td><td>".$row['CarrelliCC']."</td><td>".$row['CarrelliCC2']."</td><td>".$row['q1']."</td></tr><tr><td>carelli</td><td>".$row['Carrelli']."</td><td>".$row['Carrelli2']."</td><td>".$row['q2']."</td></tr><tr><td>rinze</td><td>".$row['Ripiani']."</td><td>".$row['Ripiani2']."</td><td>".$row['q3']."</td></tr><tr><td>pro</td><td>".$row['Prolunghe']."</td><td>".$row['Prolunghe2']."</td><td>".$row['q4']."</td></tr><tr><td>doppio</td><td>".$row['DoppieProlunghe']."</td><td>".$row['DoppieProlunghe2']."</td><td>".$row['q5']."</td></tr></table>";
    echo "<button class=btn btn-default onclick=window.print();><i class=fa fa-print></i> Print</button>";
    echo "</section>";
    }
    ?>

and its print all...all the rows...

Edited by Dani: Formatting fixed

3
Contributors
10
Replies
53
Views
3 Years
Discussion Span
Last Post by hericles
0

I'm not sure I understand. Do you want to get the next record when the user requests it (from a button or link for example)?
The WHILE loop is doing exactly what it should, loopoing through the result ser until no rows are left.
How do you want the script to work?

0

here is an example:the script it shows me
12345566
print
123123123
print
1231231233333
print

and i whant when i click second print button 123123123 to print() only that..not the usualy function print that its print all the page...

0

You would have to look at caching the result set so it was available when the print button was clicked. Or you could get one result each time and when the button is clicked call a query to get the next one. The data would need some unique identifier for this to work so you know which was the next result you wanted.
Or you could use jQuery to hide all of the elements and show the one you were up to. To do that you'd give each section a unique class attribute (e.g. its position in the array), hide all of them, and on a button click display the next section - although this may not work well depending on what and how the print function works.

0

what is wrong in this?

<?php
if(isset($_GET['id']))
{
$id=$_GET['id'];
$qry=mysql_query("SELECT FROM articles WHERE id='$id'", $con);
if(!$qry)
{
die("Query Failed: ". mysql_error());
}
else
{
echo "<br/>";
echo "a ";
echo "<br/>";
}
}
?>

if i change the SELECT with DELETE its work...why not its show me that article and only article with that id ?

0

thank you:)) i have another problem i have this code

<?php
if(isset($_GET['id']))
{
$id=$_GET['id'];
$qry=mysql_query("SELECT * FROM articles WHERE id='$id'", $con);
if(!$qry)
{
die("Query Failed: ". mysql_error());
}

while($row=mysql_fetch_array($qry))
{
echo "<table class='table table-bordered table-hover'><tr><th>/</th><th>Caricati</th><th>Scaricati</th><th>Diferenza</th></tr><tr><td>carelicc</td><td><input type='text' class='form-control' placeholder='".$row['CarelliCC']."'/><br></address></div></td><td><input type='text' class='form-control' placeholder='".$row['CarelliCC2']."' /></td><td>".$row['q1']."</td></tr><tr><td>carelli</td><td><input type='text' name='cat' id='cat' class='form-control' placeholder='".$row['Carelli']."' /></td><td><input type='text' name='cat' id='cat' class='form-control' placeholder='".$row['Carelli2']."' /></td><td>".$row['q2']."</td></tr><tr><td>rinze</td><td><input type='text' name='cat' id='cat' class='form-control' placeholder='".$row['Ripiani']."' /></td><td><input type='text' name='cat' id='cat' class='form-control' placeholder='".$row['Ripiani2']."' /></td><td>".$row['q3']."</td></tr><tr><td>pro</td><td><input type='text' name='cat' id='cat' class='form-control' placeholder='".$row['Prolunghe']."' /></td><td><input type='text' name='cat' id='cat' class='form-control' placeholder='".$row['Prolunghe2']."' /></td><td>".$row['q4']."</td></tr><tr><td>doppio</td><td><input type='text' name='cat' id='cat' class='form-control' placeholder='".$row['DoppieProlunghe']."' /></td><td><input type='text' name='cat' id='cat' class='form-control' placeholder='".$row['DoppieProlunghe2']."' /></td><td>".$row['q5']."</td></tr></table>";
}
}
?>

but i have this lines CarelliCC carelliCC2 carelli carellii2, that doesnt show up from database, and rest yes...i've double check tha columns in db and its exact the same...but it still doesnt show up that two rows...

0

SELECT * FROM articles WHERE id='$id'
would have returned all columns in the articles table. Are the columns you mention part of that table or another one? Or could they be empty strings?

0
-- --------------------------------------------------------

--
-- Structura de tabel pentru tabelul `articles`
--

CREATE TABLE IF NOT EXISTS `articles` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `category` varchar(11) NOT NULL,
  `CarrelliCC` int(11) NOT NULL,
  `CarrelliCC2` int(11) NOT NULL,
  `Carrelli` int(11) NOT NULL,
  `Carrelli2` int(11) NOT NULL,
  `Ripiani` int(11) NOT NULL,
  `Ripiani2` int(11) NOT NULL,
  `Prolunghe` int(11) NOT NULL,
  `Prolunghe2` int(11) NOT NULL,
  `DoppieProlunghe` int(11) NOT NULL,
  `DoppieProlunghe2` int(11) NOT NULL,
  `q1` int(11) NOT NULL,
  `q2` int(11) NOT NULL,
  `q3` int(11) NOT NULL,
  `q4` int(11) NOT NULL,
  `q5` int(11) NOT NULL,
  `date` date NOT NULL,
  PRIMARY KEY (`id`,`category`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=7 ;

--
-- Salvarea datelor din tabel `articles`
--

INSERT INTO `articles` (`id`, `category`, `CarrelliCC`, `CarrelliCC2`, `Carrelli`, `Carrelli2`, `Ripiani`, `Ripiani2`, `Prolunghe`, `Prolunghe2`, `DoppieProlunghe`, `DoppieProlunghe2`, `q1`, `q2`, `q3`, `q4`, `q5`, `date`) VALUES
(4, '2', 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 0, 0, 0, 0, 0, '2014-06-17');

/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
0

Can you count the size of the $row to make sure it equals the number of columns? At least then you'd know if the database is returning a complete result set.
I'd loop through the row item as a test as well, echoing for each element, just to be sure of what it contains.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.