Jump to content
php.lv forumi

datu izvade no DB njemot veeraa laiku


gkazhus

Recommended Posts

Man ir kods ar kuru meeginu izvadiit datus no DB njemot veeraa laiku un grupu kuraa lietotaajs atrodas, tik nevaru izpiipeet kluudu.

 

<p class="rtecenter" style="margin-top: 20px;">

<strong><span style="font-size: 14px;"><span style="color: rgb(193, 18, 31);">New Members</span></span></strong></p>

<?php

$con = mysql_connect("localhost","user","pwd");

if (!$con)

{

die('Could not connect: ' . mysql_error());

}

 

mysql_select_db("DB", $con);

 

$query1='';

$query2='';

$result='';

$result2 ='';

// mysql depends on selected group

if(($group==1) || ($group==2)) {

$query1 = "SELECT * FROM Members WHERE Group_ID=$group and Creation_Date >= DATE_SUB(CURDATE(), INTERVAL 2 MONTH) ORDER BY Company_Title ASC";

$query2 = "SELECT * FROM Members WHERE Group_ID=$group and Creation_Date < DATE_SUB(CURDATE(), INTERVAL 2 MONTH) ORDER BY Company_Title ASC";

$result = mysql_query($query1) or die (mysql_error());

$result2 = mysql_query($query2) or die (mysql_error());

}

else if($group==3) {

$query1 = "SELECT * FROM Members WHERE Group_ID=$group and Creation_Date >= DATE_SUB(CURDATE(), INTERVAL 1 MONTH) ORDER BY Company_Title ASC";

$query2 = "SELECT * FROM Members WHERE Group_ID=$group and Creation_Date < DATE_SUB(CURDATE(), INTERVAL 1 MONTH) ORDER BY Company_Title ASC";

$result = mysql_query($query1) or die (mysql_error());

$result2 = mysql_query($query2) or die (mysql_error());

}

else {

$query2 = "SELECT * FROM Members WHERE Group_ID=$group ORDER BY Company_Title ASC";

$result2 = mysql_query($query2) or die (mysql_error());

 

 

{

 

echo "<br />";

 

echo "<img src=\"" . $row['LOGO_lnk'] . "\" >";

echo $row['Company_Title'];

 

}

 

 

mysql_close($con);

?><br />

Edited by gkazhus
Link to comment
Share on other sites

Kura vieta tu piešķir $row vērtībās?

Šis no paraugam

<?php
$con = mysql_connect("localhost","peter","abc123");
if (!$con)
 {
 die('Could not connect: ' . mysql_error());
 }

mysql_select_db("my_db", $con);

$result = mysql_query("SELECT * FROM Persons");

while($row = mysql_fetch_array($result))
 {
 echo $row['FirstName'] . " " . $row['LastName'];
 echo "<br />";
 }

mysql_close($con);
?>

while($row = mysql_fetch_array($result))

Edited by reiniger
Link to comment
Share on other sites

Kura vieta tu piešķir $row vērtībās?

Šis no paraugam

<?php
$con = mysql_connect("localhost","peter","abc123");
if (!$con)
 {
 die('Could not connect: ' . mysql_error());
 }

mysql_select_db("my_db", $con);

$result = mysql_query("SELECT * FROM Persons");

while($row = mysql_fetch_array($result))
 {
 echo $row['FirstName'] . " " . $row['LastName'];
 echo "<br />";
 }

mysql_close($con);
?>

while($row = mysql_fetch_array($result))

 

 

 

 

$query1='';

$query2='';

$result='';

$result2 ='';

// mysql depends on selected group

if(($group==1) || ($group==2)) {

$query1 = "SELECT * FROM Members WHERE Group_ID=$group and Creation_Date >= DATE_SUB(CURDATE(), INTERVAL 2 MONTH) ORDER BY Company_Title ASC";

$query2 = "SELECT * FROM Members WHERE Group_ID=$group and Creation_Date < DATE_SUB(CURDATE(), INTERVAL 2 MONTH) ORDER BY Company_Title ASC";

$result = mysql_query($query1) or die (mysql_error());

$result2 = mysql_query($query2) or die (mysql_error());

}

else if($group==3) {

$query1 = "SELECT * FROM Members WHERE Group_ID=$group and Creation_Date >= DATE_SUB(CURDATE(), INTERVAL 1 MONTH) ORDER BY Company_Title ASC";

$query2 = "SELECT * FROM Members WHERE Group_ID=$group and Creation_Date < DATE_SUB(CURDATE(), INTERVAL 1 MONTH) ORDER BY Company_Title ASC";

$result = mysql_query($query1) or die (mysql_error());

$result2 = mysql_query($query2) or die (mysql_error());

}

else {

$query2 = "SELECT * FROM Members WHERE Group_ID=$group ORDER BY Company_Title ASC";

$result2 = mysql_query($query2) or die (mysql_error());

}

 

 

if(!empty($result)){

while ($row = mysql_fetch_array($result)) {

 

 

echo "<br />";

 

echo "<img src=\"" . $row['LOGO_lnk'] . "\" >";

echo $row['Company_Title'];

 

}

 

 

mysql_close($con);

?><br />

 

 

 

Shaadi arii veel iisti nav kaut kas liidz galam

Edited by gkazhus
Link to comment
Share on other sites

Well, forši būtu, ja izmantotu pastebin vai ko tamīdzīgu. Anyways,

Nekādus errorus neesi saņēmis no querijiem?

Cik Tev tālu sourcē var redzēt? Vajadzētu jebkurā gadījumā visticamāk redzēt <img src="">

Kā arī šis

while ($row = mysql_fetch_array($result)) {}

nepaķer arī Tavu otru queriju, kas ir zem $result2.

Nekad tik sarežģītu queriju taisījis neesmu, lai noteiktu intervālus, bet ticu, ka tos var apvienot vienā querijā.

Dod vairāk info par to, ko redzi un ko neredzi.

Kā arī pārbaudi, vai tiešām Tev tabulās ir rowi, kas saucās LOGO_lnk un Company_Title. Šādi, un ne citādi.

Lai atrastu labāko variantu datubāzes tabulās savu vajadzīgo, iesaku izmantot phpmyadmin SQL tabu.

Link to comment
Share on other sites

Well, forši būtu, ja izmantotu pastebin vai ko tamīdzīgu. Anyways,

Nekādus errorus neesi saņēmis no querijiem?

Cik Tev tālu sourcē var redzēt? Vajadzētu jebkurā gadījumā visticamāk redzēt <img src="">

Kā arī šis

while ($row = mysql_fetch_array($result)) {}

nepaķer arī Tavu otru queriju, kas ir zem $result2.

Nekad tik sarežģītu queriju taisījis neesmu, lai noteiktu intervālus, bet ticu, ka tos var apvienot vienā querijā.

Dod vairāk info par to, ko redzi un ko neredzi.

Kā arī pārbaudi, vai tiešām Tev tabulās ir rowi, kas saucās LOGO_lnk un Company_Title. Šādi, un ne citādi.

Lai atrastu labāko variantu datubāzes tabulās savu vajadzīgo, iesaku izmantot phpmyadmin SQL tabu.

 

 

Lai dabuutu aaraa vienkaarsi lietotaajus ar bildi

$result = mysql_query("SELECT * FROM Members ORDER BY Creation_Date DESC LIMIT 3");

while($row = mysql_fetch_array($result))
 {

 echo "<br />";

echo "<img src=\"" . $row['LOGO_lnk'] . "\" >";
echo $row['Company_Title'];

 }


mysql_close($con);
?><br />

 

tas viss normaali straadaa... bet man vajag lai tiktu paraadiiti lietotaaji kas registreeti peedeejos 2 meeneshu laikaa no kolonnas GROUP_ID=4 un lietotaaji kas registreeti 1 meenesi attieciigi ar GROUP_ID 1-3

Link to comment
Share on other sites

Grūti gan saprast, ko Tu vēlies un kāda ir Tava kļūda, kas nesanāk, bet no tā, ko sapratu. mēģini pa vecmodīgai metodei.

 

$year  = date("Y");
$month = date("n") - 2;

SELECT * FROM Members WHERE Group_ID=$group AND YEAR(Creation_Date)=$year AND MONTH(Creation_Date)>=$month ORDER BY Company_Title ASC

Edited by eregi
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...