Napisano: 31 Maj 2009 7:29
<?php
$hostname_LL = "localhost";
$database_LL = "database";
$username_LL = "username";
$password_LL = "password";
$LL = mysql_pconnect($hostname_LL, $username_LL, $password_LL) or trigger_error(mysql_error(),E_USER_ERROR);
mysql_select_db($database_LL, $LL);
if(isset($_GET['sortby'])){
$sortby = $_GET['sortby'];
if(strcasecmp($sortby, "desc")==0){
$newsort = "ASC";
}
else{
$newsort = "DESC";
}
}
else{
$sortby = "ASC";
$newsort = "DESC";
}
if(isset($_GET['orderby'])){
$orderby = $_GET['orderby'];
$query_sv = "SELECT `id`, `name`, `surname`, `age`, `gender`, `jmbg` FROM `artikl` ORDER BY ".mysql_real_escape_string($orderby);
if(strcasecmp($sortby, "desc")==0){
$query_sv.= " DESC";
}
else{
$query_sv.= " ASC";
}
}
//default query
else{
$query_sv = "SELECT `id`, `name`, `surname`, `age`, `gender`, `jmbg` FROM `artikl` ORDER BY naziv ASC"; }
$sv = mysql_query($query_sv, $LL) or die(mysql_error());
// $row_sv = mysql_fetch_assoc($sv);
$totalRows_sv = mysql_num_rows($sv);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<style type="text/css">
body
{
margin-top: 0;
margin-bottom: 0;
margin-left: auto;
margin-right: auto;
font: Arial, Helvetica, sans-serif;
font-family:Arial, Helvetica, sans-serif;
width: 1000px;
text-align: center;
}
p
{
margin: 0;
padding: 0;
height: 12pt;
}
#col1
{
width: 20%;
height: auto;
float: left;
text-align: center;
height: auto;
}
#col2
{
width: 20%;
height: auto;
float: left;
text-indent: inherit;
}
#col3
{
width: 20%;
height: auto;
float: left;
text-align: center;
}
#col4
{
width: 20%;
height: auto;
float: left;
text-align: right;
}
#col5
{
width: 20%;
height: auto;
float: left;
text-align: right;
}
#teble
{
width: auto;
height: auto;
}
#header
{
width: auto;
height: 12pt;
border: solid 1px #000;
}
#data
{
width: auto;
height: auto;
background-color: #CFF;
}
#foot
{
clear: both;
border-bottom: solid 1px #000;
border-top: solid 1px #000;
}
.naslov
{
float: left;
width: 20%;
background-color: #FFC;
border-bottom: solid 1px #000;
text-align: center;
text-transform: uppercase;
}
#container
{
text-align: left;
width: 1000px;
margin: 0;
padding: 0;
}
</style>
</head>
<body>
<div id="container">
<div id="table">
<div id="header">
<p class="naslov"> ID </p><p class="naslov"> Name </p><p class="naslov"> Surname </p><p class="naslov"> Age </p><p class="Gender"> JMBG </p>
</div>
<div id="data">
<div id="col1">
<?php
$num = 1;
while ($num<=$totalRows_sv)
{
echo "<p>$num</p>\n";
$num++;
}
?>
</div>
<div id="col2">
<?php while ($row_sv = mysql_fetch_assoc($sv))
{ echo "<p>" .$row_sv['name']. "</p>\n"; }
?>
</div>
<div id="col3">
<?php while ($row_sv = mysql_fetch_assoc($sv))
{ echo "<p>" .$row_sv['surname']. "</p>\n"; }
?>
</div>
<div id="col4">
<?php while ($row_sv = mysql_fetch_assoc($sv))
{ echo "<p>" .$row_sv['age']. "</p>\n"; }
?>
</div>
<div id="col5">
<?php while ($row_sv = mysql_fetch_assoc($sv))
{ echo "<p>" .$row_sv['gender']. "</p>\n"; }
?>
</div>
</div>
<div id="foot">
Ovo je podnozje tabele i cisto je tu da ima
</div>
</div>
</div>
</body>
</html>
<?php
mysql_free_result($sv);
?>
Ovo je kod kojim pokusavam da izvucem podatke iz baze podataka
ako slozim da podatke izvlacim kao redove, tj da imam TR i TD ili DIV i DIV koji su kao takvi onda skripta radi,
medjutim ja hocu da izvucem redove iz MYSQLa ali da mi podatci izlaze kao kolone
u ovom slucaju sto vidite prva kolona radi nezavisno jer je to obicni brojac dok se ne ispuni uslov i druga kolona odradi svoje kakao treba medjutim tu je kraj, treca cetvrta i peta se nista ne desava,
Znam da podatci iz MYSQLa izlaze kao nizovi [0],[1] ali neznam kako da od redova uradim kolone
Dopuna: 31 Maj 2009 7:42
Nastavak pitanja
mozda nije direktno PHP ali ima veze sa PHP i CSS
Kako da svaki drugi tj parni redovi da budu jedne boje a neparni druge, malo svetlije i tamnije
kako bi se redovi razlikovali
|